[systemd-devel] Starting a unit on resume from suspend/hibernate

Dimitrios Apostolou jimis at gmx.net
Thu Apr 2 12:24:18 PDT 2015


On Thu, 2 Apr 2015, Lennart Poettering wrote:

> On Thu, 02.04.15 18:43, Dimitrios Apostolou (jimis at gmx.net) wrote:
>
>> Hello list,
>>
>> I'm having trouble to auto-activate a unit on resume, after suspend-to-ram
>> or hibernation. The unit properly stops when suspending (because of
>> Conflicts=sleep.target), but does not restart after resuming.
>
> We do not really support that right now. Suspend/hibernate is
> implemented as a single transaction, and you cannot stop a unit
> and start it in the same transaction.

Thanks, this is a nice explanation, I wish this was documented because 
there are various hackish ways all over the internet, that might or might 
not work after much fiddling around.

>
> A hackish way to implement this is by using the suspend callout dir
> /usr/lib/systemd/system-sleep/ (see systemd-suspend.service(8) for
> details), and enqueue a stop and a start job from there, depending on
> whether the hook is called before or after the
> suspend/hibernation. But yeah, this is hackish.

So I wanted to avoid that because of dependencies - I need the units to be 
stopped in proper order, so I thought that these dependencies are better 
be expressed in the unit file. But I guess it's OK to do "systemctl 
start/stop" in the system-sleep scripts, so that will work for me.

>
> Usually if one wants to do that one is just working around some
> problems that are better solved in a different way.
>
> Why precisely do you need this feature?

I need to properly terminate system accounting, in the same way that it 
happens when shutting down, so that a relevant record is written. Same 
when resuming, I need it to be identical to booting the system.


Thanks,
Dimitris


>
> Lennart
>
> -- 
> Lennart Poettering, Red Hat
>


More information about the systemd-devel mailing list