注意:我在Medium上写了一篇文章,解释了如何创建服务以及如何避免这个特殊问题:使用systemd创建Linux服务。
原始问题:
我正在使用systemd使工作脚本始终保持工作状态:
[Unit]
Description=My worker
After=mysqld.service
[Service]
Type=simple
Restart=always
ExecStart=/path/to/script
[Install]
WantedBy=multi-user.target
尽管如果脚本在几分钟后正常退出,则重新启动可以正常工作,但是我注意到,如果脚本在启动时反复执行失败,systemd
将放弃尝试启动它:
Jun 14 11:10:31 localhost systemd[1]: test.service: Main process exited, code=exited, status=1/FAILURE
Jun 14 11:10:31 localhost systemd[1]: test.service: Unit entered failed state.
Jun 14 11:10:31 localhost systemd[1]: test.service: Failed with result 'exit-code'.
Jun 14 11:10:31 localhost systemd[1]: test.service: Service hold-off time over, scheduling restart.
Jun 14 11:10:31 localhost systemd[1]: test.service: Start request repeated too quickly.
Jun 14 11:10:31 localhost systemd[1]: Failed to start My worker.
Jun 14 11:10:31 localhost systemd[1]: test.service: Unit entered failed state.
Jun 14 11:10:31 localhost systemd[1]: test.service: Failed with result 'start-limit'.
同样,如果我的工作脚本多次失败,退出状态为255
,systemd
则放弃尝试重新启动它:
Jun 14 11:25:51 localhost systemd[1]: test.service: Failed with result 'exit-code'.
Jun 14 11:25:51 localhost systemd[1]: test.service: Service hold-off time over, scheduling restart.
Jun 14 11:25:51 localhost systemd[1]: test.service: Start request repeated too quickly.
Jun 14 11:25:51 localhost systemd[1]: Failed to start My worker.
Jun 14 11:25:51 localhost systemd[1]: test.service: Unit entered failed state.
Jun 14 11:25:51 localhost systemd[1]: test.service: Failed with result 'start-limit'.
有没有办法强制systemd
给总是在几秒钟后重试吗?
StartLimitIntervalSec=0
和遮挡。