如何设置systemd服务以30秒为周期重试5次 [英] How to set up a systemd service to retry 5 times on a cycle of 30 seconds

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

问题描述

我希望 systemd 启动脚本并重试最多 5 次,间隔 30 秒.阅读 systemd.service 手册并在互联网上搜索并没有得到任何明显的答案.

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.

推荐答案

经过多次反复试验,我解决了我的问题,并认为值得在这里发帖...

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

要允许最多 5 次重试间隔 30 秒,请使用相关 systemd 服务文件中的以下选项.

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

对于使用Type=idle"运行脚本的服务,这对我有用.请注意,'StartLimitInterval' 必须大于 'RestartSec * StartLimitBurst',否则服务将无限期重启.

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.

这篇关于如何设置systemd服务以30秒为周期重试5次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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