[systemd-devel] Custom power off

Mantas Mikulėnas grawity at gmail.com
Wed Dec 20 20:05:11 UTC 2017


On Wed, Dec 20, 2017 at 7:54 PM, Zygmunt Ptak <zygmuntptak at gmail.com> wrote:

> Hi systemd devs and users,
>
> I want to implement custom power off method.
> I added to the yocto script: /usr/sbin/halt.local which will power off
> my machine.
>
> But from what I see it is not correct.
> Ive got this from my machine:
>
> [  OK  ] Reached target Shutdown.
>          Starting /usr/sbin/halt.local Compatibility...
> My power off
> [   76.916101] EXT4-fs (mmcblk1p1): re-mounted. Opts: (null)
> [  OK  ] Started /usr/sbin/halt.local Compatibility.
> [  OK  ] Reached target Final Step.
>          Starting Power-Off...
> [   77.102708] systemd-shutdown[1]: Sending SIGTERM to remaining
> processes...
> [   77.124900] systemd-journald[203]: Received SIGTERM from PID 1
> (systemd-shutdow).
> [   77.174386] systemd-shutdown[1]: Sending SIGKILL to remaining
> processes...
> [   77.194122] systemd-shutdown[1]: Unmounting file systems.
> [   77.200107] systemd-shutdown[1]: Remounting '/var/volatile'
> read-only with options ''.
> [   77.208187] systemd-shutdown[1]: Unmounting /var/volatile.
> [   77.253911] systemd-shutdown[1]: Remounting '/tmp' read-only with
> options ''.
> [   77.261142] systemd-shutdown[1]: Unmounting /tmp.
> [   77.314075] systemd-shutdown[1]: Remounting '/' read-only with
> options 'data=ordered'.
> [   77.322732] EXT4-fs (mmcblk1p1): re-mounted. Opts: data=ordered
> [   77.328818] systemd-shutdown[1]: Remounting '/' read-only with
> options 'data=ordered'.
> [   77.336983] EXT4-fs (mmcblk1p1): re-mounted. Opts: data=ordered
> [   77.342981] systemd-shutdown[1]: Remounting '/' read-only with
> options 'data=ordered'.
> [   77.351167] EXT4-fs (mmcblk1p1): re-mounted. Opts: data=ordered
> [   77.357245] systemd-shutdown[1]: All filesystems unmounted.
> [   77.362835] systemd-shutdown[1]: Deactivating swaps.
> [   77.367923] systemd-shutdown[1]: All swaps deactivated.
> [   77.373168] systemd-shutdown[1]: Detaching loop devices.
> [   77.390252] systemd-shutdown[1]: All loop devices detached.
> [   77.395883] systemd-shutdown[1]: Detaching DM devices.
> [   77.401337] systemd-shutdown[1]: All DM devices detached.
> [   77.409285] systemd-shutdown[1]: Powering off.
> [   77.431515] reboot: System halted
>
> "My power off" will power off machine, but to early.
>
> I want to call my script after:
> "[   77.409285] systemd-shutdown[1]: Powering off."
>

Generally, programs no longer run after the computer has been powered off...

To run custom code *before* systemd powers off (or halts) the system:

a) Use a shutdown hook (man systemd-shutdown),
or b) Use a shutdown initramfs (/run/initramfs/shutdown).

-- 
Mantas Mikulėnas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20171220/3e94364f/attachment-0001.html>


More information about the systemd-devel mailing list