Yocto do_package: 未找到 SYSTEMD_SERVICE_ 中指定的服务单元

Yocto do_package: Didn't find service unit specified in SYSTEMD_SERVICE_

描述

我想在我的映像中安装一个服务,但安装失败并出现以下错误

ERROR: mypackage-git-r0 do_package: Didn't find service unit 'mypackage.service', specified in SYSTEMD_SERVICE_mypackage. 
ERROR: Logfile of failure stored in: <build-location>/poky/build/tmp/work/cortexa53-poky-linux/mypackage/git-r0/temp/log.do_package.7924
ERROR: Task (<layer-location>/meta-mypackage-oe/recipes-mypackage/mypackage/mypackage_git.bb:do_package) failed with exit code '1'

食谱

Python 源是从 git 克隆的,现在我想在启动时为 运行 创建一个服务。这是食谱

SUMMARY = " "
DESCRIPTION = " "
HOMEPAGE = " todo "
LICENSE = "CLOSED"
SRC_URI += "<URL>"

SRC_URI += "file://mypackage.service"

SRCREV   = "<srcrev>"
S        = "${WORKDIR}/git"


inherit setuptools3 systemd

RDEPENDS_${PN} = " \
    ${PYTHON_PN}-pyserial \
    ${PYTHON_PN}-pyusb \
    ${PYTHON_PN}-terminal \
"
SYSTEMD_PACKAGES = "${PN}"

do_install_append () {
    install -d ${D}${system_unitdir}
    install -m 0755 ${WORKDIR}/mypackage.service ${D}{system_unitdir}
}

SYSTEMD_SERVICE_${PN} = "mypackage.service"

FILES_${PN} += "${system_unitdir}/mypackage.service"

配方结构

recipes-mypackage/mypackage/
├── mypackage
│   └── mypackage.service
└── mypackage_git.bb

1 directory, 2 files

服务文件

注意:mypackage 具有 运行 作为守护进程的功能,使用 -d 选项

[Unit]
Description=mypackage service

[Service]
Type=simple
ExecStart=/usr/bin/mypackage -d

[Install]
WantedBy=multi-user.target

构建配置

图像配方继承core-image-base并包含

IMAGE_FEATURES += "package-management"
PACKAGE_CLASSES ?= "rpm deb package_deb"
DISTRO_FEATURES_append = " systemd"
VIRTUAL-RUNTIME_init_manager += "systemd"
inherit extrausers

local.conf 内容

MACHINE = "raspberrypi3-64"
ENABLE_UART = "1"
RPI_USE_U_BOOT = "1"
GPU_FREQ = "250"

我可能在食谱中弄乱了很多东西,所以需要一些指导来清理食谱并解决问题。

谢谢。

system_unitdir 替换为 systemd_system_unitdir

SYSTEMD_PACKAGES 已经包含 ${PN} 所以你可以忽略它,对于 FILES_${PN} += "${systemd_system_unitdir}/mypackage.service" 也是一样,就好像 systemd.bbclass 找到了你的单位,它会被添加到适当的 FILES_ 自动.

c.f。 https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/classes/systemd.bbclass#n4 https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/classes/systemd.bbclass#n109 https://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/classes/systemd.bbclass#n148

为了完整起见,感谢@Jussi Kukkonen 的评论,在 {systemd_system_unitdir} 之前缺少 $ 符号。