如何配置 systemd 服务以定期重启? [英] How can I configure a systemd service to restart periodically?

查看:75
本文介绍了如何配置 systemd 服务以定期重启?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的 systemd 服务,需要定期重新启动以防止其进程出错.systemd 服务是否有配置选项可以定期重新启动它们?所有重启*选项似乎与退出时重新启动服务有关.

I have a simple systemd service that needs to be periodically restarted to keep its process from bugging out. Is there a configuration option for systemd services to periodically restart them? All of the Restart* options seem to pertain to restarting the service when it exits.

推荐答案

是的,您可以通过将您的服务设为 Type=notify 来让您的服务定期重新启动.将此选项与 Restart=always 一起添加到您的服务文件的 [Service] 部分,并给出 WatchdogSec=xx,其中 xx 是您想要重新启动的时间段(以秒为单位)服务.在这里,您的进程将在 xx 时间段后被 systemd 杀死,并将再次被 systemd 重新启动.例如.

Yes, you can make your service to restart it periodically by making your service of Type=notify. Add this option in [Service] section of your service file along with Restart=always and give WatchdogSec=xx, where xx is the time period in second you want to restart your service. Here your process will be killed by systemd after xx time period and will be restarted by systemd again. for eg.

[Unit]
.
.

[Service]
Type=notify
.
.
WatchdogSec=10
Restart=always
.
.

[Install]
WantedBy= ....

这篇关于如何配置 systemd 服务以定期重启?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆