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

Dimitrios Apostolou jimis at gmx.net
Thu Apr 2 09:43:40 PDT 2015


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.

The key to achieve this as far as I understand, are the following two 
clauses:

After=sleep.target
WantedBy=sleep.target

The second one (WantedBy) seems to be problematic.  "systemctl show" does 
now show sleep.target in there and "systemctl enable" does not install the 
proper symlink. Even afer manually symlinking myself, the unit doesn't 
seem to be started after resuming:

ln -s /usr/lib/systemd/system/sysstat.service /etc/systemd/system/sleep.target.wants/sysstat.service

Finally I've tried replacing "sleep.target" with "suspend.target" with no 
success. The system logs are showing no errors, and my systemd version is 
systemd-216-21.fc21.i686.  You can see the full unit file here:


[Unit]
Description=System Activity Accounting
# Start the periodic accounting process
Requires=sysstat-collect.timer
# but make sure we finish first, because the accounting process locks the datafile
Before=sysstat-collect.timer sysstat-collect.service

# Automatically stop the unit when starting sleep.target
Conflicts=sleep.target
# and start it again after resume (in combination with WantedBy at the end)
After=sleep.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/lib/sa1 --boot -C STARTED
ExecStop=/usr/lib/sa1 --boot -C STOPPED

[Install]
WantedBy=multi-user.target sleep.target
Also=sysstat-collect.timer
Also=sysstat-summary.timer



Any ideas what might be wrong? I understand a workaround would be to 
install custom scripts under the "system-sleep" directory, but if the 
problem can be solved within the unit file, that would be ideal.

Thanks in advance,
Dimitris

P.S. Please keep me CC'd as I'm not subscribed. Let me know if this is not 
the proper place for such questions, I'd appreciate pointers to the 
relevant list.



More information about the systemd-devel mailing list