Do systems using systemd read and execute scripts in /etc/pm/sleep.d/ ?

I'm starting to concluded the answer is that systemd ignores these scripts. If this is true what is the replacement?

Update: man systemd-sleep states scripts can be added to /lib/systemd/system-sleep/. The details were insufficient for me but I tried a modification of an Arch wiki example and created /lib/systemd/system-sleep/root-resume.service.

[Unit]
Description=Local system resume actions
After=suspend.target

[Service]
Type=simple
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target

My intention is to restart network-manager after resuming because occasionally it isn't working.

This doesn't seem to be doing what I want.

up vote 12 down vote accepted

Scripts in /etc/pm/config.d|power.d|sleep.d are ignored under systemd. Instead a systemd "unit" (service) must be created and enabled.

To restart networking after the system resumes from sleep I created the file /lib/systemd/system/root-resume.service:

[Unit]
Description=Local system resume actions
After=suspend.target

[Service]
Type=oneshot
ExecStart=/bin/systemctl restart network-manager.service

[Install]
WantedBy=suspend.target

Then I activated the service with sudo systemctl enable root-resume.service. Enabling the service creates a symbolic link for the file in /etc/systemd/system/suspend.target.wants/

Contrary to man systemd-sleep service files placed in /lib/systemd/system-sleep/ are ignored.

  • Yes, exactly this was the reason why the "restart network after a suspend" scripts were not working for people running ubuntu with systemd. – neo1691 Jul 1 '15 at 6:17
  • This should be created as /etc/systemd/system/root-resume.service. You should never modify files under /lib as they are managed by the package manager, to avoid cruft and potential breakages on upgrade, not to mention simplifying backups. – hackel Sep 6 '16 at 21:22

No, nor those in /usr/lib/pm-utils/sleep.d. But it runs all scripts (not service files) in /lib/systemd/system-sleep/ with executable bits set.

Here's an example one for calling pm-powersave, modified from /usr/lib/pm-utils/sleep.d/00powersave.

#!/bin/sh

# do not run pm-powersave on ARM during suspend; the 1.5 seconds that it takes
# to run it don't nearly compensate the potentially slightly slower suspend
# operation in low power mode
ARCH=`uname -m`

case $1 in
    pre)  [ "$ARCH" != "${ARCH#arm}" ] || pm-powersave false ;;          
    post) pm-powersave ;;
esac
exit 0

$1 is "post" on resume, "pre" otherwise. $2 in both cases contains either "suspend", "hibernate", or "hybrid-sleep".

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.