首页 > 解决方案 > Yocto 将第三个系统服务添加到配方文件导致其他人无法启动

问题描述

我正在修改 Yocto .bb 配方文件以在我的图像中添加和启用 3 个 systemd 服务。下面显示了我的配方文件的底部,其中仅添加并启用了两项服务。这行得通!

app1.service 是一个一次性的基本服务,运行一次,app2.service 通过在 app2.service 文件中使用“ After=app1.service”等待 app1.service 首先完成。所有这些都可以正常工作,没有问题:

FILES_${PN} += "${sysconfdir} \
               ${systemd_unitdir}/system/app1.service \
               ${systemd_unitdir}/system/app2.service \
"
inherit systemd

SYSTEMD_SERVICE_${PN} = "app1.service app2.service"

现在,我添加了名为 app3.service 的第三个服务,如下所示。该服务也应该以同样的方式首先等待 app1.service 完成

FILES_${PN} += "${sysconfdir} \
               ${systemd_unitdir}/system/app1.service \
               ${systemd_unitdir}/system/app2.service \
               ${systemd_unitdir}/system/app3.service \

"
inherit systemd

SYSTEMD_SERVICE_${PN} = "app1.service app2.service app3.service"

但是,当我启动设备时,只有 app3.service 运行,app1.service 和 app2.service 报告以下内容,告诉我该服务未以某种方式启用:

app1.service - app1
Loaded: loaded (/lib/systemd/system/app1.service; disabled; vendor 
preset: enabled)
Active: inactive (dead)

这是我无法理解的。我希望所有三个服务都启用,因为我将它们添加到 SYSTEMD_SERVICE_${PN}。

以我在 .bb 配方文件中的方式添加三个服务是否有问题?谢谢

应用程序1.服务:

[Unit]
Description=app1 
ConditionPathExists=/app
After=network.target uncrypte_app.service uncrypte_data.service

[Service]
Type=oneshot
WorkingDirectory=/app
ExecStart=/app/app1
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

app2.服务:

[Unit]
Description=app2 
ConditionPathExists=/app
After=network.target uncrypte_app.service uncrypte_data.service app1.service

[Service]
Type=simple
WorkingDirectory=/app
ExecStartPre=/bin/rm -f /var/run/app2.pid
ExecStart=/app/app2 start
ExecStop=/app/app2 stop
RemainAfterExit=yes
Restart=on-failure

[Install]
WantedBy=multi-user.target

app3.服务:

[Unit]
Description=app3
ConditionPathExists=/storage
After=network.target uncrypte_app.service uncrypte_data.service app1.service

[Service]
WorkingDirectory=/storage
ExecStart=/storage/app3
RemainAfterExit=yes
Restart=on-failure

[Install]
WantedBy=multi-user.target

标签: linuxyoctosystemdbitbakerecipe

解决方案


因为配方继承了 systemd 类,你有没有尝试定义SYSTEMD_AUTO_ENABLE变量?

这个变量:

指定您在 SYSTEMD_SERVICE 中指定的服务是否应自动启动。

您可以将以下行添加到您的自定义包配方中

  SYSTEMD_AUTO_ENABLE_${PN} = "enable"

推荐阅读