How to set up a systemd service to retry 5 times on a cycle of 30 seconds

时光总嘲笑我的痴心妄想 提交于 2019-12-09 07:55:50

问题


I want systemd to start a script and retry a maximum of 5 times, 30s apart. Reading the systemd.service manual and searching the Internet didn't produce any obvious answers.


回答1:


After much trial and error I solved my problem and thought it worth posting here...

To allow a maximum of 5 retries separated by 30 seconds use the following options in the relevant systemd service file.

[Unit]
StartLimitInterval=200
StartLimitBurst=5
[Service]
Restart=always
RestartSec=30

This worked for me for a service that runs a script using 'Type=idle'. Note that 'StartLimitInterval' must be greater than 'RestartSec * StartLimitBurst' otherwise the service will be restarted indefinitely.



来源:https://stackoverflow.com/questions/39284563/how-to-set-up-a-systemd-service-to-retry-5-times-on-a-cycle-of-30-seconds

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!