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

Lennart Poettering lennart at poettering.net
Fri Aug 9 08:46:50 PDT 2013


On Wed, 07.08.13 10:12, Mathijs Kwik (mathijs at bluescreen303.nl) wrote:

> Hi all,
> 
> I have a few things that need to get run after waking up my laptop
> (things like hdparm to set device power options/spindown time).
> I created oneshot, remainafterexit services for those and made them
> wanted by multi-user.target.This works fine for the first boot.
> 
> As I consider these services "dead" after a suspend/hibernate, I added
> Conflicts=sleep.target, so now systemd is aware that these services
> are no longer active after a wakeup.
> 
> Now I would like to somehow have these services restart on wakeup.
> I can add these services to some new target(wakeup.target), but I
> don't know how to proceed from there. I thought of making
> wakeup.target WantedBy suspend.target, After suspend.target, but since
> suspend.target pulls in sleep.target (which conflicts with these
> services) that will fail. More so, after wakeup.target is started the
> first time, it will never go down itself, so the second wakeup won't
> do anything. The same is true for multi-user.target, once that is
> reached/activated on first boot, it never deactivates until shutdown.
> 
> How should a situation like this be handled?
> Ideally, I don't want to use:
> - /usr/lib/systemd/system-sleep  (considered hacky)

Well, doing hdparm fiddling after suspend is a hack in itself, hence
/usr/lib/systemd/system-sleep/ is precisely the right hacky choice to
implement something like this. It's simple, synchronous and the intended
place to put hacks like this.

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the systemd-devel mailing list