【发布时间】:2019-07-06 17:50:21
【问题描述】:
我想添加自定义 yocto systemd 服务。
我提到了Enable systemd services using yocto
但我的 bb 代码不起作用。它没有安装在文件系统中。 (eth0.service 代码没问题)
如何解决?
eth0_0.1.bb
SUMMARY = "Install and start a systemd service"
SECTION = "eth0"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/MIT;md5=0835ade698e0bcf8506ecda2f7b4f302"
SRC_URI += "file://eth0.service"
S = "${WORKDIR}"
inherit systemd
SYSTEMD_SERVICE_${PN} = "eth0.service"
do_install() {
install -d ${D}${systemd_system_unitdir}
install -m 0644 ${WORKDIR}/eth0.service ${D}${systemd_system_unitdir}/
}
FILES_${PN} += "/lib/systemd/system"
REQUIRED_DISTRO_FEATURES= "systemd"
eth0.service
[Unit]
Description=Network interfaces
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys.subsystem-net-devices-eth0.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "ifup eth0"
ExecStop=/bin/sh -c "ifdown eth0"
[Install]
WantedBy=multi-user.target
【问题讨论】:
-
您是否通过例如将其添加到图像中? IMAGE_INSTALL_append = local.conf 中的“eth0”
-
@Khem 哦,我很愚蠢。有用!我通过 do_install() 建立了符号链接。 'ln -sf ${systemd_unitdir}/system/eth0.service \ ${D}${sysconfdir}/systemd/system/multi-user.target.wants/eth0.service' 但错误 -> ln: 未能创建符号关联。怎么了?
-
如果你有
inherit systemd和SYSTEMD_SERVICE_${PN} = "eth0.service",你不需要做符号链接。所以我认为您需要添加的是SYSTEMD_AUTO_ENABLE = "enable"并确保 .service 文件具有您似乎也有的 [Install] 部分。