了解 systemd 是否真正启用

了解 systemd 是否真正启用

我想确定某项服务是否已启用。

使用 SysV Init 很容易。但是使用 则systemctl status <service name>很混乱,而且 systemd 太复杂,难以深入研究。

具体来说,我尝试启用

# systemctl enable watchdog.service

但重启后它给了我这个状态:

# systemctl status watchdog.service
● watchdog.service - watchdog daemon
   Loaded: loaded (/lib/systemd/system/watchdog.service; static; vendor preset: enabled)
   Active: inactive (dead)

但我无法理解为什么它已启用但发生了某些事情,或者启用服务命令是否失败。

在任何时候,手动启动服务都可以:

# systemctl start watchdog.service
# systemctl status watchdog.service
● watchdog.service - watchdog daemon
   Loaded: loaded (/lib/systemd/system/watchdog.service; static; vendor preset: enabled)
   Active: active (running) since Qua 2016-12-21 04:03:26 BRST; 2s ago
  Process: 9111 ExecStart=/bin/sh -c [ $run_watchdog != 1 ] || exec /usr/sbin/watchdog $watchdog_options (code=exited, sta
  Process: 9109 ExecStartPre=/bin/sh -c [ -z "${watchdog_module}" ] || [ "${watchdog_module}" = "none" ] || /sbin/modprobe
 Main PID: 9115 (watchdog)
   CGroup: /system.slice/watchdog.service
           └─9115 /usr/sbin/watchdog

watchdog[9115]: int=1s realtime=yes sync=no soft=no mla=24 mem=0
watchdog[9115]: ping: no machine to check
watchdog[9115]: file: no file to check
watchdog[9115]: pidfile: no server process to check
systemd[1]: Started watchdog daemon.
watchdog[9115]: interface: no interface to check
watchdog[9115]: temperature: no sensors to check
watchdog[9115]: test=none(0) repair=none(0) alive=/dev/watchdog heartbeat=none to=root no_act=
watchdog[9115]: watchdog now set to 15 seconds
watchdog[9115]: hardware watchdog identity: Broadcom BCM2835 Watchdog timer

答案1

systemctl status告诉我们该单位的状态static

# systemctl status watchdog.service
● watchdog.service - watchdog daemon
   Loaded: loaded (/lib/systemd/system/watchdog.service; static; vendor preset: enabled)
   Active: inactive (dead)

man systemctl

static” | 该单元文件未启用,并且在“ ”单元文件部分中没有启用的规定[Install]

[Install]这基本上意味着服务文件中没有部分,因此您无法通过 启用它systemctl enable。启用此类单元的方法是将其拉入依赖链,即使其成为其他单元所需或想要的。

相关内容