0

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/)
  • Try writing to another directory e.g create /home/tim/tmpdir and chmod 777 it and write to there. Many services under systemd have "private" /tmp directories. – Stephen Harris Dec 3 '18 at 0:52
  • You edits did not do what I said. mkdir /home/tim/tmpdir and chmod 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 3 '18 at 1:06
  • OK, good. So those changes now rule out a potential confounding factor, and so make the question clearer. I don't know why you're following an ArchLinux procedure when you're running a Ubuntu derivative, but at least we've cleared up one possible failure mode. – Stephen Harris Dec 3 '18 at 1:18
  • 2
    And now you get a downvote because your question was based on "why doesn't /tmp/mylog" appear, when you had additional knowledge. I don't appreciate having my time wasted on partial questions and partial knowlege. – Stephen Harris Dec 3 '18 at 1:32
  • Tim, you make it really really hard for people to even want to help you. You've just received the equivalent of many $$$ in consulting, and then attack the person trying to help you because you didn't provide the right information up front. – Stephen Harris Dec 3 '18 at 1:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.