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

How can I find failed systemd services?

· 52CE 我爱测

When I run systemctl status on a specific server, I get the following output: ● ⟨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: / … How can I find out which…

问题原文

原帖链接 · Patrick J. S. · CC BY-SA 4.0

When I run systemctl status on a specific server, I get the following output:

● ⟨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: /
…

How can I find out which of the services is the one that failed?

I tried it with systemctl is-failed '*', but that doesn't yield any meaningful output (it outputs 39 lines active one failed line and then some more (> 100) activelines…).

已采纳解答

原帖链接 · Patrick J. S. · CC BY-SA 3.0

It seems like is-failed is the wrong sub command… who would have guessed.

here is some perl hackery to get the right answer:

$ 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'.

And systemctl is also that nice to clutter stderr with informational output in a way that we only get the output we want.

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

资料来源与适用范围

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

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

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