14

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.

1
  • I found that /etc/pm/sleep.d scripts will still be run if you type sudo pm-suspend from cmdline. Just systemd will not use it from its workflow.
    – Tomofumi
    Aug 13, 2019 at 3:21

2 Answers 2

13

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.

2
  • 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, 2015 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, 2016 at 21:22
3

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".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .