【问题标题】:how to add recipe for yocto systemd service如何为 yocto systemd 服务添加配方
【发布时间】: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 systemdSYSTEMD_SERVICE_${PN} = "eth0.service",你不需要做符号链接。所以我认为您需要添加的是SYSTEMD_AUTO_ENABLE = "enable" 并确保 .service 文件具有您似乎也有的 [Install] 部分。

标签: yocto systemd recipe


【解决方案1】:

如果您有inherit systemdSYSTEMD_SERVICE_${PN} = "eth0.service",您似乎应该这样做。所以我认为你需要添加的是SYSTEMD_AUTO_ENABLE = "enable"a 确保.service 文件有[Install] 部分,你似乎也有。其次还要确保通过IMAGE_INSTALL_append = " eth0"local.conf将包添加到图像中

【讨论】:

    【解决方案2】:

    对于网络,您还可以创建一个 systemd_%.bbappend

    FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
    
    SRC_URI += "file://eth0.network"
    
    FILES_${PN} += "${systemd_unitdir}/network/*"
    
    do_install_append() {
        install -d ${D}${systemd_unitdir}/network/
        install -m 0644 ${WORKDIR}/*.network ${D}${systemd_unitdir}/network/
    }
    

    files/eth0.network:

    [Match]
    Name=eth0
    
    [Network]
    DHCP=ipv4
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-01
      • 2020-05-11
      • 1970-01-01
      • 1970-01-01
      • 2018-11-12
      • 2021-12-29
      • 2021-02-24
      相关资源
      最近更新 更多