Following https://wiki.archlinux.org/index.php/Power_management#Hooks_in_/usr/lib/systemd/system-sleep, I add a shell script as a systemd sleep hook with execution permission (I manually created
/usr/lib/systemd/system-sleep/ which didn't exist by default):
$ ls /usr/lib/systemd/system-sleep/ -l total 4 -rwxr-xr-x 1 root root 322 Dec 2 19:28 systemd_suspend_cpu_freq.sh
whose content is
#!/bin/sh case "$1/$2" in post/*) echo "systemd_suspend hook" >>/tmp/mylog ;; esac
I first suspend my Lubuntu 18.04, by
$ systemctl suspend User testme is logged in on seat0. User testme is logged in on sshd. User testme is logged in on seat0. User testme is logged in on seat0. Please retry operation after closing inhibitors and logging out other users. Alternatively, ignore inhibitors and users with 'systemctl suspend -i'. $ systemctl suspend -i $
Then I wake it up, and I don't find anything in
/tmp/mylog supposed to be written by my script, and also
$ journalctl -b -u systemd-suspend.service -- Logs begin at Mon 2018-11-12 13:25:27 EST, end at Sun 2018-12-02 19:30:04 EST. -- Dec 02 18:38:05 ocean systemd: Starting Suspend... Dec 02 18:38:05 ocean systemd-sleep: Suspending system... Dec 02 18:51:16 ocean systemd: Started Suspend. Dec 02 19:29:30 ocean systemd: Starting Suspend... Dec 02 19:29:30 ocean systemd-sleep: Suspending system... Dec 02 19:29:42 ocean systemd-sleep: /dev/sda: Dec 02 19:29:42 ocean systemd-sleep: setting Advanced Power Management level to 0xfe (254) Dec 02 19:29:42 ocean systemd-sleep: APM_level = 254 Dec 02 19:29:35 ocean systemd-sleep: System resumed. Dec 02 19:29:42 ocean systemd: Started Suspend.
I was wondering why my script isn't executed when waking up from suspension?
The following suggestions in the comment doesn't make the hook execute upon waking up:
mkdir /home/t/tmpdir; chmod 777 /home/t/tmpdir
- redirection to
/home/t/tmpdir/mylogin the script (no file was created under