[systemd-devel] Fwd: best way to handle service restarts after hibernate/suspend?

Mathijs Kwik mathijs at bluescreen303.nl
Wed Aug 7 23:32:34 PDT 2013


孙冰 <subi.the.dream.walker at gmail.com> writes:

> I use this:
> ----------------------------------------
> [Unit]
> Description=Wicd sleep hook
> Before=sleep.target
> StopWhenUnneeded=yes
>
> [Service]
> Type=oneshot
> RemainAfterExit=yes
> ExecStart=-/usr/share/wicd/daemon/suspend.py
> ExecStop=-/usr/share/wicd/daemon/autoconnect.py
>
> [Install]
> WantedBy=sleep.target
> -----------------------------------------

Clever :)

It turns out I always misinterpreted the documentation for
StopWhenUnneeded. I never read past the first sentence and assumed this
option was only going to stop services "when it felt like it".

But this is a very nice solution, still stateful (remainafterexit) but
by focusing on the sleep-state instead of the before-sleep and
after-sleep it nicely works around cyclic/conflicting dependencies.

Thanks!



More information about the systemd-devel mailing list