如果失败,‘systemctl is-active ...’将返回什么?

如果失败,‘systemctl is-active ...’将返回什么?

如果我执行systemctl is-active <service-name>,当服务处于活动状态但失败时,结果代码的值是什么?0(成功)还是其他?

答案1

好吧,根据我自动重启脚本最近的一次故障,它似乎systemctl --quiet is-active <service-name>返回了0,这在某种程度上与active(failed)我记得的旧的故障案例中获得的详细输出是有意义的。

解决方案可能是检查失败相反,考虑到我不需要在我的服务被明确停止的情况下自动重启它(原始命令将返回非0,其详细输出inactive自然包含),并且考虑到我希望在失败的

答案2

如果失败,则状态为“不活动”。如果我正确理解了您的问题,我重现了它:

brad@zika:~$ systemctl is-active fwupd-refresh
inactive
brad@zika:~$ systemctl status fwupd-refresh
○ fwupd-refresh.service - Refresh fwupd metadata and update motd
     Loaded: loaded (/lib/systemd/system/fwupd-refresh.service; static)
     Active: inactive (dead) since Wed 2022-04-27 08:00:12 EDT; 2h 51min ago
TriggeredBy: ● fwupd-refresh.timer
       Docs: man:fwupdmgr(1)
    Process: 1899748 ExecStart=/usr/bin/fwupdmgr refresh (code=exited, status=1/FAILURE)
   Main PID: 1899748 (code=exited, status=1/FAILURE)
        CPU: 262ms

Apr 27 08:00:06 zika.gattaca.net systemd[1]: Starting Refresh fwupd metadata and update motd...
Apr 27 08:00:12 zika.gattaca.net systemd[1]: fwupd-refresh.service: Main process exited, code=exited, status=1/FAILURE
Apr 27 08:00:12 zika.gattaca.net systemd[1]: fwupd-refresh.service: Failed with result 'exit-code'.
Apr 27 08:00:12 zika.gattaca.net systemd[1]: Failed to start Refresh fwupd metadata and update motd.
brad@zika:~$ 

相关内容