[systemd-devel] Halt then reboot

Andrei Borzenkov arvidjaar at gmail.com
Sat Sep 17 06:05:55 UTC 2016


16.09.2016 20:20, Dark Penguin пишет:
> Greetings!
> 
> Short version: is it possible with systemd to have the machine halt,
> wait for a few minutes and then reboot?
> 

When system halts OS kernel is stopped and control is returned to
firmware. So the only thing you can do is to program firmware to reboot
after some delay.

> Long version:
> Many UPS-es do not support cutting power at all, or ignore the command
> to cut the power in certain situations. There was a workaround for that:
> instead of powering the machines off, they had to halt, then wait a
> reasonable amount of time (during which the UPS should turn off), and
> then reboot - in case power came back and the UPS did not power-cycle
> its load.
> 

This is fragile as you have no idea whether power returned or not and
risk hard power off in the middle of next boot.

> Now that systemd manages the shutdown procedure, I don't know if it's
> possible to achieve the same behaviour (and thus make NUT work with
> systemd).

As already mentioned, it is ouside of scope of OS actually. How you did
it before systemd?

> But since it's systemd, maybe we can make this even better!
> There were some concerns that it's not a good idea to simply "halt the
> system"; what we should do is flush all the drives' cache and unload
> their heads, which can only be done *properly* from the kernel. (See
> this old Debian bug:
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=358696 ) So maybe with
> systemd, we can actually not simply "halt" the system, but make all the
> necessary preparations in order to ensure that cutting power is safe?
> 
> 

So your question is misleading. You did not halt (in proper sense) but
rather left OS lingering before doing halt.

systemd supports switching back to initramfs instead of directly halting
system. This allows you to implement your logic there after everything
is completely shut down and unmounted (you probably need to unmount old
root manually though). You can even monitor UPS from initramfs and only
reboot when it reports power is back to make it safe.



More information about the systemd-devel mailing list