Search code examples
yoctoyocto-recipe

Yocto: add a statement in the default service file within a recipe


I'd need to add a Restart statement within a default .service file, and was looking to an alternate solution to replacing the .service file with a custom one (which works).

The idea would be just adding the following "delta" requirement in a, e.g., ${systemd_system_unitdir}/my_service.d/override.conf file:

[Service]
Restart=always

and then adding that file in a dedicated .bbappend recipe file.

Tests so far were not successful in adding the above statements in the deployed service file (despite the "delta" conf file being correctly deployed). Is this even a possible solution?


Solution

  • You should be able to do that simply by echoing that entry in a do_install:append() section in you .bbappend file. Something like:

    do_install:append() {
        echo "[Service]\nRestart=always" >> ${D}${sysconfdir}/wpa_supplicant/...
    }
    

    You can equally use sed to find and replace that section if there is already a file inplace.

    ${sysconfdir} will expanded to /etc. Check this file for more defined path variables: https://git.yoctoproject.org/poky/plain/meta/conf/bitbake.conf?h=blinky