Yocto SYSTEMD_SERVICE to install a parameterized service ("@.service")

Viewed 2015

I need to configure WireGuard to bring up a VPN on boot on an Embedded Linux device.

My recipe installs a /etc/wireguard/wg0.conf pretty much like the examples found through the Internet.

Then I try to enable the service on SystemD like this on my wireguard.bb:

SYSTEMD_SERVICE = "wg-quick@wg0.service"
SYSTEMD_AUTO_ENABLE = "enable"

But bitbake throws me an error:

ERROR: Function failed: SYSTEMD_SERVICE_my-conf value wg-quick@wg0.service does not exist

I checked the temporary directory and file wg0.conf appears in the correct places but it seems that bitbake's SYSTEMD_SERVICE doesn't know how to expand the "wg0" after @ sign.

If I try without the interface name (wg0):

SYSTEMD_SERVICE = "wg-quick@.service"

Bitbake is happy and finalizes my recipe, but it is not what systemd is expecting. Starting a service without an interface makes no sense...


Then I tried another approach and split the "wireguard" package itself from the configuration ("wireguard-conf" package) and added DEPENDS and RDEPENDS on "wireguard".

This got even worse since my wireguard-conf.bb recipe does not contain a "wg-quick@.service" file (it comes from the dependency "wireguard").


Well,

I don't know how to properly fix it and any suggestions will be highly appreciated.


Additional Info

I am using Yocto 2.0.3 in this project (with no hope of updating it).

Thanks to @TomasNovotny comments I managed to compare my "systemd.bbclas" against Github and noticed a change in systemd_populate_packages() that seems to solve the problem.

2 Answers

It works in newer OpenEmbedded (looks like in krogoth, version 2.1 released Apr 2016) and it is introduced by this commit. It works for me in rocko (version 2.4 released Oct 2017). According to j4x's comment, it doesn't work in jethro (version 2.0, Nov 2015).

For older (and currently unsupported OpenEmbeddeds) you can try to backport the patch or handle the symlinks for enabling the service in do_install().

Also please note that SYSTEMD_SERVICE_${PN} variable is package specific, so the _${PN} suffix has to be added (see manual).

I've also tried to enable OpenVPN with my profile (in Yocto rocko) without success. Finally, I've made it working by providing OpenVPN recipe extension instead of custom one. So, the openvpn_%.bbappend file looks like:

inherit systemd
SYSTEMD_SERVICE_${PN} = "openvpn@clientprofile.service"
SYSTEMD_AUTO_ENABLE = "enable"

do_install_append() {
    install -d ${D}${sysconfdir}/openvpn/
    ln -sf /data/etc/openvpn/clientprofile.conf ${D}${sysconfdir}/openvpn/clientprofile.conf
}

As you can see, I'm using a symlink to my profile instead of the normal file. You can install a normal OpenVPN profile file instead of making symlink and it also works fine.

Related