Disable a standard systemd service in Yocto build
Asked Answered
R

5

7

I need to start my own systemd service, let's call it custom.service. I know how to write a recipe for it to be added and enabled on boot:

SYSTEMD_SERVICE_${PN} = "custom.service"
SYSTEMD_AUTO_ENABLE_${PN} = "enable"

However, it conflicts with one of the default systemd services - systemd-timesyncd.service.

Is there a nice preferred way to disable that default systemd service in my bitbake file even though the systemd_XX.bb actually enables it?

I can create a systemd_%.bbappend file to modify the systemd settings, but I can't locate the place where one service can be disabled leaving all others enabled.


The working solution I found is to remove the timesyncd altogether using

PACKAGECONFIG_remove = "timesyncd"

But I wonder if this is a appropriate way and if there is a way to just disable it, but leave in the system.

Roxanneroxburgh answered 1/6, 2018 at 21:48 Comment(1)
Did you write the PACKAGECONFIG:remove = "timesyncd" in a .../recipes-core/systemd/systemd_%.bbappend or in another file? This doesn't seem to have any effect for me.Cline
C
5

If the system runs fine with the other package removed, then removing the package is a preferred solution. Fewer packages means a simpler system.

Carven answered 2/6, 2018 at 11:26 Comment(0)
W
13

How about adding a .bbappend recipe for the conflicting service you want disabled. In it, you would add: SYSTEMD_AUTO_ENABLE_${PN} = "disable"

Woolfell answered 23/1, 2019 at 3:41 Comment(1)
This works but for the new bitbake you need to use like this: SYSTEMD_AUTO_ENABLE:${PN} = "disable"Soloist
C
5

If the system runs fine with the other package removed, then removing the package is a preferred solution. Fewer packages means a simpler system.

Carven answered 2/6, 2018 at 11:26 Comment(0)
C
3

Usually you would set SYSTEMD_AUTO_ENABLE_${PN} = "disable" and that would let the service be part of image but disabled on boot. However for systemd which provides a lot of default service units this may not be a solution you might want to deploy. You could surgically delete the symlink in etc which will ensure that service is not started automatically on boot but the .service file is still part of image. So add following to systemd_%.bbappend file in your layer

do_install_append() {
        rm -rf ${D}${sysconfdir}/systemd/system/sysinit.target.wants/systemd-timesyncd.service
} 

There are other ways to disable this e.g. using systemd presets as described here

Cantillate answered 2/6, 2018 at 18:5 Comment(0)
L
2

Use the systemd.preset — Service enablement presets and in particular following steps.

  • Create a .bbappend file meta-xxx/recipes-core/systemd/systemd_%.bbappend with this content:
do_configure_append() {
    #disabling autostart of systemd-timesyncd
    sed -i -e "s/enable systemd-timesyncd.service/disable systemd-timesyncd.service/g" ${S}/presets/90-systemd.preset
}

In my yocto-based Linux distribution (yocto zeus release) above steps are enough to disable the service which remains installed. In the output distribution previous steps modify the file /lib/systemd/system-preset/90-systemd.preset.
After the modification, in that file, appear the row: disable systemd-timesyncd.service and this row substitutes the raw: enable systemd-timesyncd.service

At this link there are some information about the topic: systemd.preset — Service enablement presets.

Other useful.


I was not able to use SYSTEMD_AUTO_ENABLE_${PN} = "disable" in this context. For other recipes (for example dnsmasq_2.82.bb) the previous assignment works correctly and I have used it to enable (or disable) a service in the yocto distribution.

Ligneous answered 3/10, 2022 at 10:41 Comment(0)
W
-2

I think the "official" way to do this is to have something like this somewhere in your project:

PACKAGECONFIG_append_pn-systemd = "--disable-timesyncd"

This does basically the same you already suggested. To simply not enable the service you have to do it manually since you can modify the auto enable only per recipe.

Walkover answered 5/6, 2018 at 11:29 Comment(2)
Sorry @Caspar, I've tried this and the service was still there running.Roxanneroxburgh
WARNING: systemd-1_230+gitAUTOINC+3a74d4fc90-r0 do_configure: QA Issue: systemd: invalid PACKAGECONFIG: --disable-timesyncd [invalid-packageconfig]Lactose

© 2022 - 2024 — McMap. All rights reserved.