yocto - 使用 yocto 启用 systemd 服务

标签 yocto bitbake

嗨,这是我的图层树

├── 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 not found。
我之前尝试在 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 recipe 的正确方法吗?写这个的意义是什么?
#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} 作为其他脚本需要的脚本。
  • 没有理由拥有 do_install_append()在 bb 文件中:您可以将所有内容放入 do_install()
  • 如果您的 Yocto 是最新的,请使用 ${systemd_system_unitdir}而不是 /lib/systemd/system是个好主意(在旧版本中 ${systemd_unitdir}/system/ 有效)
  • 关于yocto - 使用 yocto 启用 systemd 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45614578/

    相关文章:

    yocto - 在任何 yocto 系统中,apt-get 或 yum 的等价物是什么?

    yocto - Yocto 中的共享状态缓存如何工作?

    compiler-errors - Yocto nativesdk-ncurses无法构建,因为包含路径未以sysroot前缀

    linux - init-ifupdown 的 Yocto Poky-Pyro bbappend 文件没有替换/etc/network/interfaces

    yocto - 如何在 core-image-minimal yocto 中更改初始化系统

    linux - 使用SDK编译模块抛出警告消息: libelf-dev not found

    bitbake - 如何让 Openembedded 编译 tar.gz 文件而不是 tar.xz

    kernel - yocto bitbake 配置文件位置

    c++ - 是否可以通过包含头文件来实现运行时依赖性?

    package - 如何避免在 BitBake 构建期间尝试安装之间的文件冲突?