Disable a standard systemd service in Yocto build

邮差的信 提交于 2019-12-13 12:32:45

问题


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.


回答1:


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




回答2:


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




回答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




回答4:


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.



来源:https://stackoverflow.com/questions/50651371/disable-a-standard-systemd-service-in-yocto-build

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!