linux - 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
解决方案
因为配方继承了 systemd 类,你有没有尝试定义SYSTEMD_AUTO_ENABLE
变量?
这个变量:
指定您在 SYSTEMD_SERVICE 中指定的服务是否应自动启动。
您可以将以下行添加到您的自定义包配方中
SYSTEMD_AUTO_ENABLE_${PN} = "enable"
推荐阅读
- c# - 存储一个没有服务定位器的 Unity 依赖注入容器
- tfs - 从 Team Foundation 服务帐户组中删除非活动用户
- r - 在 R 的 1 个绘图区域中放置 4 个直方图
- typescript - 如何为 Angular 8 中的选项卡编写点击事件
- ionic-framework - 按类别过滤产品
- asp.net - 如何对在 localhost 上运行的 .NET 项目的 API 调用失败进行故障排除?
- mysql - 将 GROUP BY 与 MAX()/MIN() 一起使用会产生不好的结果
- google-apps-script - Google 驱动器权限 api 仅在 20 次调用后引发速率限制错误
- python - 使用请求将变量插入 Python 中的 SQL 查询
- java - Java正则表达式和“贪婪”或早期搜索斜线