0

I want to add custom yocto systemd service.

I referred to Enable systemd services using yocto

but my bb code is not working. It's not installed in filesystem. (eth0.service code is okay)

How to fix it?

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
phuclv
  • 37,963
  • 15
  • 156
  • 475
dev j
  • 39
  • 3
  • 6
  • have you added it to image via e.g. IMAGE_INSTALL_append = " eth0" in local.conf – Khem Feb 13 '19 at 01:26
  • @Khem oh i'm stupid. it works! and i made symbolic link by do_install(). 'ln -sf ${systemd_unitdir}/system/eth0.service \ ${D}${sysconfdir}/systemd/system/multi-user.target.wants/eth0.service' but error -> ln: failed to create symbolic link. what's wrong? – dev j Feb 13 '19 at 04:10
  • 1
    you dont need to do symlinking if you have `inherit systemd` and `SYSTEMD_SERVICE_${PN} = "eth0.service"` which you seem to have. So I think what you need to add is `SYSTEMD_AUTO_ENABLE = "enable"` and make sure that .service file has [Install] section which you seem to have as well. – Khem Feb 13 '19 at 06:22

2 Answers2

1

if you have inherit systemd and SYSTEMD_SERVICE_${PN} = "eth0.service" which you seem to have should have done it. So I think what you need to add is SYSTEMD_AUTO_ENABLE = "enable" a nd make sure that .service file has [Install] section which you seem to have as well. Secondly also make sure package is added to image via IMAGE_INSTALL_append = " eth0" in local.conf

Khem
  • 1,162
  • 8
  • 8
1

For network you can also create a systemd_%.bbappend with

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/
}

with files/eth0.network:

[Match]
Name=eth0

[Network]
DHCP=ipv4
Nayfe
  • 2,130
  • 13
  • 18