定时重启一个服务的几种方法

spider · · 897 次点击 · 开始浏览    置顶
这是一个创建于 的主题,其中的信息可能已经有所发展或是发生改变。
本文以 Ubuntu 18.04 为例,介绍如何在 Linux 下使 systemd 服务定时重启。有几种不同的方法。 ** crontab ** 注意,此种方法在 root 用户下使用最佳,普通用户的 --user 服务会有许多问题需要解决。 `30 3 * * * /bin/systemctl restart your_service` `crontab -l cronjob` ** RuntimeMaxSec ** ``` [Service] Restart=always RuntimeMaxSec=604800 ``` ** timer ** a-restart.service ``` [Unit] Description=Restart Service [Service] Type=oneshot ExecStart=/bin/systemctl try-restart some-service.service ``` a-restart.timer ``` [Unit] Description=Reboot Scheduling [Timer] OnCalendar=*-*-* 01:30:00 [Install] WantedBy=timers.target ``` `systemctl enable a-restart.timer` ** WatchdogSec ** ``` [Service] WatchdogSec=10 Restart=always ```

关注本站微信公众号(和以上内容无关)InfraPub ,扫码关注:InfraPub

897 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传