Reputation: 4938
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.
Upvotes: 7
Views: 25006
Reputation: 1257
Usually you would set SYSTEMD_AUTO_ENABLE_${PN} = "disable"
and that would let the service be part of the 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 the service is not started automatically on boot but the .service file is still part of image. So add the following to the 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
Upvotes: 4
Reputation: 2513
Use the systemd.preset — Service enablement presets and in particular following steps.
.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 is 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.
Upvotes: 2
Reputation: 141
How about adding a .bbappend recipe for the conflicting service you want disabled. In it, you would add:
SYSTEMD_AUTO_ENABLE_${PN} = "disable"
Upvotes: 14
Reputation: 1
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.
Upvotes: -2
Reputation: 13381
If the system runs fine with the other package removed, then removing the package is a preferred solution. Fewer packages means a simpler system.
Upvotes: 5