[systemd-devel] How to reboot from within a service
Lennart Poettering
lennart at poettering.net
Mon Apr 19 14:02:38 UTC 2021
On So, 18.04.21 12:01, Norbert Lange (nolange79 at gmail.com) wrote:
> Hello,
>
> My setup is some embedded system without logind, running a service
> that should be able to poweroff, reboot or reboot-and-update.
> Generally I guess this also includes triggering further services
> programmatically fron another.
>
> 1) As I do currently: send SIGRTMIN+5 to PID1
> (not really the complete solution, would need to discern between
> reboot/update).
> 2) exec 'systemctl start reboot.target'
> basically a variant of 1).
> 3) Same thing as 2), but do it with dbus or varlink.
> 4) Some unknown and likely not existing configuration of unit files.
> doing something like "IfExitCode=121 then start reboot.target"
> 5) Use the Watchdog and let it expire.
>
> While working, I would expect the first 3 options to be depended on
> various level of rights to interfere with
> PID1, aswell as being systemd specific (using dbus or systemd DSO).
> Some sort of separation between
If you want to reboot the system in a sysv compatible way you can only
fork off "reboot" or "shutdown -r", or maybe send SIGINT to PID 1. The
latter is pretty ugly though, since this will be treated as if people
actually used Ctlr-Alt-Del on the console by PID 1, i.e. this is
subject to misleading log messages and the reboot hard after hitting
this 7x in 2s.
> advertising the need for reboot and acting on it would be cleaner (ie.
> hooking it up in service files).
>
> What are the best option(s) here?
Use logind's D-Bus APIs. It's the cleanest way to reboot, as it
honours inhibitors and stuff.
Lennart
--
Lennart Poettering, Berlin
More information about the systemd-devel
mailing list