我如何找到失败的 systemd 服务?

我如何找到失败的 systemd 服务?

当我systemctl status在特定服务器上运行时,我得到以下输出:

● ⟨host-name⟩
    State: degraded
     Jobs: 0 queued
   Failed: 1 units
    Since: Fr 2017-06-09 00:34:27 UTC; 1 weeks 5 days ago
   CGroup: /

我如何才能找出哪个服务失败了?

我尝试过systemctl is-failed '*',但没有产生任何有意义的输出(它输出active一行39 行failed,然后又输出一些(> 100)active行...)。

答案1

尝试

sudo systemctl list-units --failed

或者

sudo systemctl list-units --state=failed

答案2

这似乎is-failed是错误的子命令……谁能想到呢。

这里有一些 perl 技巧可以得到正确答案:

$ systemctl list-units | perl -lanE'print if $F[2] !~ /active/'
  UNIT    LOAD   ACTIVE SUB       DESCRIPTION
● vboxautostart-service.service                                                             loaded failed failed    vboxautostart-service.service

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

207 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

并且systemctl用信息输出来扰乱 stderr 也很好,这样我们只能得到我们想要的输出。

相关内容