使用yocto启用systemd服务
嗨,这是我的图层树使用yocto启用systemd服务,yocto,bitbake,Yocto,Bitbake,嗨,这是我的图层树 ├── conf │ └── layer.conf ├── COPYING.MIT ├── README └── recipes-hello ├── helloworld │ ├── helloworld-0.1 │ │ ├── helloworld.c │ │ ├── helloworld.patch │ │ └── newhelloworld.c │ └── helloworld_0.1.
├── conf
│ └── layer.conf
├── COPYING.MIT
├── README
└── recipes-hello
├── helloworld
│ ├── helloworld-0.1
│ │ ├── helloworld.c
│ │ ├── helloworld.patch
│ │ └── newhelloworld.c
│ └── helloworld_0.1.bb
├── message
│ ├── message-0.1
│ │ └── message.txt
│ └── message_0.1.bb
└── service
├── service-0.1
│ ├── test_systemd.service
│ └── test_systemd.sh
└── service_0.1.bb
这里test_systemd.service是必须调用test_systemd.sh的服务文件,我正试图使用service_0.1.bb实现它
# This recipe performs the following tasks
# 1) Install .sh file in /home/root/ and .sh script creates a random text file
# 2) Install the .service file in systemd directory
# 3) Invoke the .sh script via .service file
inherit systemd
SUMMARY = "Install and start a systemd service"
SECTION = "examples"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
#here we specify the source we want to build
SRC_URI = "file://test_systemd.sh"
SRC_URI += "file://test_systemd.service"
#here we specify the source directory, where we can do all the building and expect sources to be placed
S = "${WORKDIR}"
SYSTEMD_SERVICE_${PN} = "test_systemd.service"
#bitbake task
#created a directory /home/root for target install the script
do_install() {
install -d ${D}/home/root
install -m 0755 ${WORKDIR}/test_systemd.sh ${D}/home/root
install -d ${D}{systemd_system_unitdir}
install -m 0644 ${WORKDIR}/test_systemd.service ${D}{systemd_system_unitdir}
}
#Pack the path
FILES_${PN} += "/home/root"
FILES_${PN} += "/lib/systemd/system"
REQUIRED_DISTRO_FEATURES= "systemd"
问题是,当我尝试bitbake系统配方时,bitbake抛出一个错误,表示找不到test_systemd.service。
我以前尝试过在RFS中安装这两个文件,但我加入了systemd概念。我得到的结论是没有这样的文件错误。原因可能是什么?
错误消息
NOTE: Executing SetScene Tasks
NOTE: Executing RunQueue Tasks
ERROR: service-0.1-r0 do_package: SYSTEMD_SERVICE_service value test_systemd.service does not exist
ERROR: service-0.1-r0 do_package: Function failed: systemd_populate_packages
ERROR: Logfile of failure stored in: /home/guest/yocto_practice/poky/build-beaglebone/tmp/work/cortexa8hf-neon-poky-linux-gnueabi/service/0.1-r0/temp/log.do_package.2860
ERROR: Task (/home/guest/yocto_practice/meta-testlayer/recipes-hello/service/service_0.1.bb:do_package) failed with exit code '1'
NOTE: Tasks Summary: Attempted 514 tasks of which 506 didn't need to be rerun and 1 failed.
Summary: 1 task failed:
/home/guest/yocto_practice/meta-testlayer/recipes-hello/service/service_0.1.bb:do_package
Summary: There were 2 ERROR messages shown, returning a non-zero exit code.
这也是为systemd编写bb配方的正确方法吗?写这篇文章的意义是什么
#Pack the path
FILES_${PN} += "/home/root"
FILES_${PN} += "/lib/systemd/system"
如果没有这个bitbake就会抛出错误
SYSTEMD_SERVICE_${PN} += "file://test_systemd.service"
这应该是:
SYSTEMD_SERVICE_${PN} = "test_systemd.service"
其他注意事项(与错误无关):
- 将东西安装到/home中可能不是一个好主意(您可以使用其他脚本需要的脚本,例如
)${libexecdir}
- 没有理由在bb文件中有一个
:您可以将所有内容都放在do\u install\u append()
do\u install()
- 如果您的Yocto是最新的,那么使用
而不是${systemd\u unitdir}
是一个好主意(在较旧的版本中/lib/systemd/system
工作)${systemd\u unitdir}/system/
do_install() {
install -d ${D}${bindir}
install -m 0755 ${WORKDIR}/test_systemd.sh ${D}${bindir}
install -d ${D}${systemd_unitdir}/system
install -m 0644 ${WORKDIR}/test_systemd.service ${D}${systemd_unitdir}/system
}
感谢您为mods提供建议。我根据您做了更改,但仍然收到错误。将更新问题我仍然收到相同的错误。不知道为什么bitbake无法在文件存在的位置找到该文件。您当前的配方两次引用了
${D}{systemd\u system\u unitdir}
。它应该是${D}${systemd\u system\u unitdir}
。否则它在这里工作。