侧边栏壁纸
博主头像
奇楠木语博主等级

行动起来,活在当下

  • 累计撰写 138 篇文章
  • 累计创建 94 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

systemd 添加简单定时参数

Administrator
2019-08-13 / 0 评论 / 0 点赞 / 176 阅读 / 1353 字

日常用的 debian 10 有一个服务需要常驻并且定时重启 , 一般的解决方案是单独加一个 crontab . 但是咱们既然用了 debian 10 并且写了 systemd 配置文件 , 那找找有没有可以实现定时重启的参数 .

在 linux service/daemon systemd 配置文件中 , 有一个参数可以实现此功能 .

RuntimeMaxSec= Configures a maximum time for the service to run

以下是原文链接 :
https://www.freedesktop.org/software/systemd/man/systemd.service.html#RuntimeMaxSec=

使用此参数记得 restart=always , 具体自己的服务要配置什么参数 , 看文档吧 .
贴一下我的通用 systemd 文件

[Unit]
Description= Custom Server Service
Documentation=man:htop
After=network.target

[Service]
Type=simple
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
User=root
LimitNOFILE=65536

StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=python-server

Restart=always
RuntimeMaxSec=28800
ExecStart=/usr/bin/python /path/to/file/server.py

[Install]
WantedBy=multi-user.target

Post time: 2019-08-13

0

评论区