Why is my script not executed when waking up from systemd suspension?











up vote
0
down vote

favorite












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/)










share|improve this question
























  • 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 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 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 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 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 at 1:39















up vote
0
down vote

favorite












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/)










share|improve this question
























  • 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 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 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 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 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 at 1:39













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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/)










share|improve this question















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/)







ubuntu systemd suspend






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 3 at 12:21

























asked Dec 3 at 0:40









Tim

25.4k73243447




25.4k73243447












  • 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 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 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 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 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 at 1:39


















  • 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 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 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 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 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 at 1:39
















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 at 0:52




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 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 at 1:06






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 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 at 1:18




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 at 1:18




2




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 at 1:32




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 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 at 1:39




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 at 1:39















active

oldest

votes











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485593%2fwhy-is-my-script-not-executed-when-waking-up-from-systemd-suspension%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f485593%2fwhy-is-my-script-not-executed-when-waking-up-from-systemd-suspension%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Morgemoulin

Scott Moir

Souastre