为什么我的 systemd 服务没有自动启动?

RQD*_*QDQ 3 systemd yocto

这是我的 boondocks-agent.service 文件。我已经将它安装在 /lib/systemd/system 中:

[Unit]
Description=Boondocks agent
Requires=\
    balena.service 
After=\
    balena.service 

[Service]
Type=simple
Restart=always
RestartSec=10s
WatchdogSec=60
EnvironmentFile=/etc/boondocks-agent/agent.conf
EnvironmentFile=-/tmp/boondocks-agent.conf
ExecStartPre=-/usr/bin/stop-boondocks-agent
ExecStart=/usr/bin/healthdog --healthcheck=/usr/lib/boondocks-agent/boondocks-agent-healthcheck  /usr/bin/start-boondocks-agent
ExecStop=-/usr/bin/stop-boondocks-agent

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

当我启动系统时,它似乎没有启动。干净启动后,这是我看到的状态:

systemctl status boondocks-agent
boondocks-agent.service - Boondocks agent
   Loaded: loaded (/lib/systemd/system/boondocks-agent.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能在启动时自动启动?

编辑

在 YOCTO 中,相当于调用的systemctl enable是:

SYSTEMD_SERVICE_${PN} = " \
    boondocks-agent.service
    "
Run Code Online (Sandbox Code Playgroud)

小智 6

你说,

在 YOCTO 中,相当于调用的systemctl enable是:

   SYSTEMD_SERVICE_${PN} = " \
       boondocks-agent.service
       "
Run Code Online (Sandbox Code Playgroud)

我认为这相当于安装服务。要使服务默认启用,您需要添加:

SYSTEMD_AUTO_ENABLE_${PN} = "enable"
Run Code Online (Sandbox Code Playgroud)

  • SYSTEMD_AUTO_ENABLE 是 per-default true,如果配方继承了 systemd 类。因此,不应要求将其显式设置为 true。请参阅 https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#var-SYSTEMD_AUTO_ENABLE (2认同)

Big*_*gon 4

您需要在启动时启用它:

systemctl enable boondocks-agent