Yocto将第三系统服务添加到配方文件会导致其他人无法启动

时间:2019-06-13 17:39:26

标签: linux yocto systemd bitbake recipe

我正在修改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配方文件中的方式添加三个服务是否存在问题?谢谢

app1.service:

[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.service:

[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.service:

[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

1 个答案:

答案 0 :(得分:0)

由于配方继承了systemd类,您是否尝试定义SYSTEMD_AUTO_ENABLE变量?

此变量:

  

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

您可以将以下行添加到您的自定义包装食谱中

  SYSTEMD_AUTO_ENABLE_${PN} = "enable"