大网数据广告活动
服务器运维问答

Systemd execute command after start limit reached

· 52CE 我爱测

I've been working on a systemd service to wrap an administration script and I'm trying to gracefully handle it completely breaking. Right now I have Restart set to always so it will try again when something fails, but some failur…

问题原文

原帖链接 · Will · CC BY-SA 3.0

I've been working on a systemd service to wrap an administration script and I'm trying to gracefully handle it completely breaking.

Right now I have Restart set to always so it will try again when something fails, but some failure states require attention (missing config file, bad SQL, etc), so I don't want it continuously spinning in the background in an uncorrectable state.

I found StartLimitInterval, StartLimitBurst, and StartLimitAction, which stops trying to restart it after X failures in Y seconds, but it turns out that the only actions available for StartLimitAction are rebooting or shutting down the machine, which is a little overkill.

I've been looking at OnFailure and wrote a mini service to send an alert email when it's triggered, but OnFailure triggers every time the service dies, not when it hits the start limit, so we get a bunch of emails instead of just one.

Any ideas of what to try next?

已采纳解答

原帖链接 · Haystack · CC BY-SA 4.0

From the systemd.unit man page:

OnFailure=

A space-separated list of one or more units that are activated when this unit enters the "failed" state. A service unit using Restart= enters the failed state only after the start limits are reached.

However the second sentence appears to be a new constraint, as it is in the manual for version 241 of systemd on my Arch installations, but not in version 219 on my CentOS 7 installation.

You can check your systemd version with systemctl --version

I know it's an old question but just wanted to share for anyone else who has the same problem.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。