Bug 80082

Summary: Suspend/Hibernate should have StopWhenUnneeded=yes
Product: systemd Reporter: m8r-0s9a4g
Component: generalAssignee: systemd-bugs
Status: RESOLVED INVALID QA Contact: systemd-bugs
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description m8r-0s9a4g 2014-06-16 07:43:44 UTC
I want to have a unit that starts/stops on suspend (but not hibernate).

Using WantedBy=sleep.target works for suspend or hibernate, but WantedBy=suspend.target will not work because systemd-suspend.service doesn't have StopWhenUnneeded=yes.

Is there any downside to add StopWhenUnneeded to suspend? Is there any other way to have a service stop/stop based on suspend that I'm missing?
Comment 1 Lennart Poettering 2014-06-20 11:58:51 UTC
Not following here. systemd-suspend.service terminates as soon as the suspend is complete, on its own, because it does exit(0), there's no point of adding StopWhenUnneeded=yes to it. Don't grok the problem.

Your service should be able to do BindTo=systemd-suspend.service and Before=systemd-suspend.service. That way, its ExecStart= should be invoked before, and its ExecStop= after the suspend.

Also note the hook directory in /usr/lib/systemd/system-sleep/. See systemd-sleep(8) for details.
Comment 2 m8r-0s9a4g 2014-06-25 04:11:23 UTC
Looks like BindsTo=systemd-suspend.service and Before=systemd-suspend.service does what I want.

I guess my confusion is why does suspend.target stay active after resuming when sleep.target doesn't?

I don't think I'm the only one confused by it. The Arch wiki[1] has examples with suspend.target and sleep.target. I don't think the suspend.target ones will work as expected.

[1] https://wiki.archlinux.org/index.php/Power_management#Suspend.2Fresume_service_files

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.