由 systemd 控制的已停止的自定义服务不会出现在 systemctl list-units --full --all 中

由 systemd 控制的已停止的自定义服务不会出现在 systemctl list-units --full --all 中

我们在 ubuntu 中开发了自定义服务,并且为 systemd 安装和启用了它们。

使用 systemctl stop 停止这些自定义服务时,已停止的服务不会出现在“systemctl list-units --full --all”CLI 中。服务启动运行正常,并且出现在 list-units 输出中。

我需要能够列出已加载但已停止的单元。请注意,“systemctl list-unit-files --full --all”确实会显示自定义服务。但该 CLI 仅适用于“已启用”服务,而不适用于“已加载”服务,因此对我们来说没有用。

其他默认服务(例如 sshd/postfix 等)在停止时会出现 list-units 列表。

有什么线索/建议可以帮助我弄清楚出了什么问题吗?

我的 ubuntu 和 systemd 版本如下。服务模板也在下面给出

Systemd 详细信息

systemd --version
systemd 229
+PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN

Ubuntu 版本

   cat /etc/os-release
   NAME="Ubuntu"
   VERSION="16.04.2 LTS (Xenial Xerus)"
   ID=ubuntu
   ID_LIKE=debian
   PRETTY_NAME="Ubuntu 16.04.2 LTS"
   VERSION_ID="16.04"
   HOME_URL="http://www.ubuntu.com/"
   SUPPORT_URL="http://help.ubuntu.com/"
   BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
   VERSION_CODENAME=xenial
   UBUNTU_CODENAME=xenial

服务模板

[Unit]
Description=Custom Service
Requires=dependent_1.service dependent_2.service custom_init.service
Wants=networking.service
After=custom_init2.service custom2.service
[email protected]

[Service]
Type=simple
ExecStart=/opt/foo/bar/libexec/custom_service_exe
ExecStartPost=/opt/foo/bar/libexec/notify_state_change %p 1
ExecStopPost=/opt/foo/bar/libexec/notify_state_change %p 0

ExecReload=/bin/kill -HUP $MAINPID
Restart=always
StartLimitInterval=450
StartLimitBurst=3

[Install]
RequiredBy=custom.target

相关内容