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[1]: Starting Suspend...
Dec 02 18:38:05 ocean systemd-sleep[17888]: Suspending system...
Dec 02 18:51:16 ocean systemd[1]: Started Suspend.
Dec 02 19:29:30 ocean systemd[1]: Starting Suspend...
Dec 02 19:29:30 ocean systemd-sleep[20436]: Suspending system...
Dec 02 19:29:42 ocean systemd-sleep[20436]: /dev/sda:
Dec 02 19:29:42 ocean systemd-sleep[20436]: setting Advanced Power Management level to 0xfe (254)
Dec 02 19:29:42 ocean systemd-sleep[20436]: APM_level = 254
Dec 02 19:29:35 ocean systemd-sleep[20436]: System resumed.
Dec 02 19:29:42 ocean systemd[1]: Started Suspend.
I was wondering why my script isn't executed when waking up from suspension?
Thanks.
Update
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/mylog
in the script (no file was created under/home/t/tmpdir/
)
/home/tim/tmpdir
andchmod 777
it and write to there. Many services under systemd have "private"/tmp
directories. – Stephen Harris Dec 03 '18 at 00:52mkdir /home/tim/tmpdir
andchmod 777 /home/tmp/tmpdir
(or whatever your home directory is) and then write to that./tmp/test/mylog
is a subdirectory of/tmp
and so may be part of a private/tmp
tree. – Stephen Harris Dec 03 '18 at 01:06/home/tim/tmpdir
? You say the change Stephen suggested doesn't make the hook ruin (it wasn't supposed to). Does that mean that even when writing to/home/tim/tmpdir
you see no file created after waking up? – terdon Dec 03 '18 at 10:56