在预定义的时间内没有生成输出时,是否可以重新启动systemd服务?
我有一个显然可以挂起的脚本,但是systemd(或Python)无法检测到该脚本,因此它不会进入失败状态。
但是,它确实停止记录输出,因此在一分钟内未给出任何输出后,我应该能够重新启动服务。systemd有可能吗?
我当前的systemd文件:
[Unit]
Description=SOmething
After=network.target
[Service]
WorkingDirectory=/home/user/system/something
User=nobody
ExecStart=/usr/bin/python2 something.py
Restart=on-watchdog
RestartSec=10s
[Install]
WantedBy=multi-user.target
我不认为systemd允许您这样做,至少systemd.service(5)
手册页面似乎没有提到类似的内容。
但是,您可以做的是使用systemd的内置看门狗。
你会做到这一点的设置WatchdogSec=
,然后有把你的服务WATCHDOG=1
与sd_notify
定期。如果设置,WatchdogSec=30
则您的服务必须最多每30秒通知系统一次。
当您的服务挂起时,它将不再通知systemd,因此systemd将终止您的服务。
使用restart=on-watchdog
(您已经拥有,但是如果没有它就什么也不能做WatchdogSec=
),然后systemd在被看门狗杀死后,将重新启动您的服务。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句