重启失败的 systemd 服务显示为不活动而不是失败

重启失败的 systemd 服务显示为不活动而不是失败

考虑以下服务:

[Unit]
Description=foobar

[Service]
Type=simple
ExecStart=/usr/bin/false
Restart=on-failure

[Install]
WantedBy=multi-user.target

我预计它会重新启动几次,然后作为故障单元停止运行。然而,这是在带有 Ubuntu Xenial 的 systemd 229 上实际发生的情况:

root@monitoring:/etc/systemd/system# systemctl status foobar
● foobar.service - foobar
   Loaded: loaded (/etc/systemd/system/foobar.service; disabled; vendor preset: 
   Active: inactive (dead)

Apr 01 21:08:43 monitoring.ci.ezyang.com systemd[1]: foobar.service: Service hol
Apr 01 21:08:43 monitoring.ci.ezyang.com systemd[1]: Stopped foobar.
Apr 01 21:08:43 monitoring.ci.ezyang.com systemd[1]: Started foobar.
Apr 01 21:08:43 monitoring.ci.ezyang.com systemd[1]: foobar.service: Main proces
Apr 01 21:08:43 monitoring.ci.ezyang.com systemd[1]: foobar.service: Unit entere
Apr 01 21:08:43 monitoring.ci.ezyang.com systemd[1]: foobar.service: Failed with
Apr 01 21:08:44 monitoring.ci.ezyang.com systemd[1]: foobar.service: Service hol
Apr 01 21:08:44 monitoring.ci.ezyang.com systemd[1]: Stopped foobar.
Apr 01 21:08:44 monitoring.ci.ezyang.com systemd[1]: foobar.service: Start reque
Apr 01 21:08:44 monitoring.ci.ezyang.com systemd[1]: Failed to start foobar.

重要的是,它不会在 中列为故障单元systemctl --failed,也不会降低 的状态systemctl status。为什么?

答案1

这是 systemd 中的一个错误,已在 systemd 238 以及可能更早的版本中修复。

[root@866d9b9835e0 system]# systemctl status foobar
* foobar.service - foobar
   Loaded: loaded (/etc/systemd/system/foobar.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2018-04-01 21:06:21 UTC; 14min ago
  Process: 143 ExecStart=/usr/bin/false (code=exited, status=1/FAILURE)
 Main PID: 143 (code=exited, status=1/FAILURE)

Apr 01 21:06:21 866d9b9835e0 systemd[1]: foobar.service: Service hold-off time over, scheduling restart.
Apr 01 21:06:21 866d9b9835e0 systemd[1]: foobar.service: Scheduled restart job, restart counter is at 5.
Apr 01 21:06:21 866d9b9835e0 systemd[1]: Stopped foobar.
Apr 01 21:06:21 866d9b9835e0 systemd[1]: foobar.service: Start request repeated too quickly.
Apr 01 21:06:21 866d9b9835e0 systemd[1]: foobar.service: Failed with result 'exit-code'.
Apr 01 21:06:21 866d9b9835e0 systemd[1]: Failed to start foobar.
[root@866d9b9835e0 system]# systemctl --version
systemd 238
+PAM -AUDIT -SELINUX -IMA -APPARMOR +SMACK -SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN +PCRE2 default-hierarchy=hybrid

Restart您可以通过避免在 systemd 中使用来解决该问题。

相关内容