How to enabled systemd unit files automatically using recipe?


Sourabh Hegde
 

Hello,

This might not be directly related to Yocto.

I have a systemd .path unit file that restarts the system service if the file changes. But, the path ubit file needs to be enabled once to make this work. So, my question is when I flash new image on the device will the path unit file enabled automatically by systemctl? Or should I do this manually using "systemctl enable --now *.path" ? Is there any way to make this work using Yocto recipe?

The custome systemd service files are installed in dir "${D}${systemd_unitdir}/system/".

Thanks in advance


Sergei Nikulov
 

On Tue, Oct 25, 2022 at 9:29 AM Sourabh Hegde <hrsourabh011@...> wrote:

Hello,

This might not be directly related to Yocto.

I have a systemd .path unit file that restarts the system service if the file changes. But, the path ubit file needs to be enabled once to make this work. So, my question is when I flash new image on the device will the path unit file enabled automatically by systemctl? Or should I do this manually using "systemctl enable --now *.path" ? Is there any way to make this work using Yocto recipe?

The custome systemd service files are installed in dir "${D}${systemd_unitdir}/system/".

Thanks in advance

You should add you file to your bb recipe SYSTEMD_SERVICE:${PN} = "file.path"

https://docs.yoctoproject.org/current/ref-manual/classes.html?highlight=systemd_service

--
Best Regards,
Sergei Nikulov


Sourabh Hegde
 

Hello Sergei,

Thanks for the update.

I have already added "SYSTEMD_SERVICE:${PN}" to my recipe. But, it is set to different file(.service file). Can I add multiple files to it?


Sergei Nikulov
 

Yes, sure.
Use space to separate multiple paths
For example:
SYSTEMD_SERVICE:${PN} = "one.service two.service one.path two.path"

On Tue, Oct 25, 2022 at 10:31 AM Sourabh Hegde <hrsourabh011@...> wrote:

Hello Sergei,

Thanks for the update.

I have already added "SYSTEMD_SERVICE:${PN}" to my recipe. But, it is set to different file(.service file). Can I add multiple files to it?

--
Best Regards,
Sergei Nikulov


Sourabh Hegde
 

Cool. Thanks again


Sourabh Hegde
 

I have a question here:

If I something like below in my recipe

SYSTEMD_SERVICE:${PN} = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'one.service', '', d)}"

Then, can I add multiple files with:

SYSTEMD_SERVICE:${PN} = "${@bb.utils.contains('DISTRO_FEATURES', 'systemd', 'one.service one.path two.service two.path', '', d)}"

?

Is this valid? Or should I use only SYSTEMD_SERVICE:${PN} = "one.service two.service one.path two.path" ?

Thanks in advance