<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[ubuntu - run the script before sleeping and after waking up the PC]]></title><description><![CDATA[<p dir="auto">Hello everyone, can I ask for help? I’m sorry, I’m using a translator, I can’t speak English.<br />
I am using the new Ubuntu, where I have Domoticz server and MagicMirror running.<br />
after 15 minutes the PC goes to sleep and then wakes up with PIR (ESP8266).</p>
<p dir="auto">After waking up, it takes a long time for the domoticz server to start working and sending Information to MagicMirror. I don’t want to solve it with service monitor.</p>
<p dir="auto">I would like to set up a script:</p>
<p dir="auto">before putting the PC to sleep run “sudo service <a href="http://domoticz.sh" target="_blank" rel="noopener noreferrer nofollow ugc">domoticz.sh</a> stop”<br />
after waking up the PC run “sudo service <a href="http://domoticz.sh" target="_blank" rel="noopener noreferrer nofollow ugc">domoticz.sh</a> start”<br />
it works reliably in the command line, it just needs a password that I enter and it’s ok.</p>
<p dir="auto">I saw somewhere that something like this can be used, but I don’t know exactly where to write, save and that it doesn’t ask for a password. Would someone be willing to write the exact procedure where to write what and save? I found a lot of versions and maybe I got it wrong or the instructions are for older Ubuntu</p>
<p dir="auto">First of all thank you very much for the joy and newbie to ubuntu.</p>
<pre><code>#!/bin/sh

PATH=/sbin:/usr/sbin:/bin:/usr/bin

case "$1" in
    pre)
            #code execution BEFORE sleeping/hibernating/suspending
    ;;
    post)
            #code execution AFTER resuming
    ;;
esac

exit 0

</code></pre>
<p dir="auto"><img src="/assets/uploads/files/1729635861963-sn%C3%ADmek2.jpg" alt="Snímek2.jpg" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.magicmirror.builders/topic/19071/ubuntu-run-the-script-before-sleeping-and-after-waking-up-the-pc</link><generator>RSS for Node</generator><lastBuildDate>Thu, 11 Jun 2026 10:32:40 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/19071.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 22 Oct 2024 22:25:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Sat, 26 Oct 2024 22:16:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/majsoft" aria-label="Profile: majsoft">@<bdi>majsoft</bdi></a> ok, here is the doc I found</p>
<p dir="auto">Suggesting to read this manual page:</p>
<p dir="auto"><a href="https://www.man7.org/linux/man-pages/man8/systemd-sleep.8.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.man7.org/linux/man-pages/man8/systemd-sleep.8.html</a></p>
<p dir="auto">Especially this section:</p>
<p dir="auto">Immediately before entering system suspend and/or hibernation<br />
systemd-suspend.service (and the other mentioned units, respectively)</p>
<p dir="auto">will run all executables</p>
<p dir="auto">in <em><strong>/usr/lib/systemd/system-sleep/</strong></em> and pass <em><strong>two</strong></em> arguments to them.</p>
<p dir="auto">The first argument will be “pre”,<br />
the second either “suspend”, “hibernate”, “hybrid-sleep”, or “suspend-then-hibernate”</p>
<p dir="auto">depending on the chosen action. An environment variable called “SYSTEMD_SLEEP_ACTION” will be set and contain the sleep action that is processing. This is primarily helpful for “suspend-then-hibernate” where the value of the variable will be “suspend”, “hibernate”, or “suspend-after-failed-hibernate” in cases where hibernation has failed.</p>
<p dir="auto">Immediately after leaving system suspend and/or hibernation the same executables are run, but the first argument is now <em><strong>“post”.</strong></em></p>
<p dir="auto">All executables in this directory are executed in parallel, and execution of the action is not continued until all executables have finished.</p>
<hr />
<p dir="auto">so your script should go in that folder… and of course be set with permissions to be executable by root</p>
<p dir="auto">see the chmod and chgrp commands</p>
<p dir="auto">the permissions are in three sections<br />
for the current user<br />
for the a group (the user might be in)<br />
for all other</p>
<p dir="auto">when you do ls -laF somefile (i picked a text file)<br />
-rw-rw-r-- 1 sam sam 8087 Oct 26 08:59 somefile.txt<br />
the permissions are<br />
user rw-  (rear/write but not executable<br />
group rw-       (read/write but not executable)<br />
and all others r--  (read only)<br />
that is 3 bits each +1 so 10 bits of permission<br />
usually represented by a number<br />
in this case 664<br />
7 is all bits on 111<br />
0 is all bits off 000<br />
chmod has shortcuts too  chmod +x make executable for all sections<br />
chmod -w makes it not writeble for all</p>
<p dir="auto">so if you want to make a file  read/write and executable by bob, read only for anyone in group testers, and NO access for anyone else (other)<br />
740 bob testers<br />
chown  and chgrp  are used to set the owner and group</p>
<p dir="auto">in linux most commands have help with the --help  parameter chown --help<br />
and most have a manual page with more text<br />
the get the manual page, type<br />
man command_name<br />
like<br />
man chown</p>
]]></description><link>https://forum.magicmirror.builders/post/120844</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120844</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sat, 26 Oct 2024 22:16:38 GMT</pubDate></item><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Mon, 28 Oct 2024 13:07:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/majsoft" aria-label="Profile: majsoft">@<bdi>majsoft</bdi></a> yeh, that one opened by me!</p>
<p dir="auto">fairly slow w fixes</p>
]]></description><link>https://forum.magicmirror.builders/post/120872</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120872</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 28 Oct 2024 13:07:59 GMT</pubDate></item><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Mon, 28 Oct 2024 10:43:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a></p>
<p dir="auto">i looked on <a href="https://github.com/Unitech/pm2/issues/5820" target="_blank" rel="noopener noreferrer nofollow ugc">github</a> but i can’t see or find a fix.</p>
]]></description><link>https://forum.magicmirror.builders/post/120871</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120871</guid><dc:creator><![CDATA[majsoft]]></dc:creator><pubDate>Mon, 28 Oct 2024 10:43:49 GMT</pubDate></item><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Mon, 28 Oct 2024 10:19:22 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/majsoft" aria-label="Profile: majsoft">@<bdi>majsoft</bdi></a> cool</p>
<p dir="auto">pm2 on 24, will review</p>
]]></description><link>https://forum.magicmirror.builders/post/120870</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120870</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 28 Oct 2024 10:19:22 GMT</pubDate></item><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Mon, 28 Oct 2024 10:48:21 GMT]]></title><description><![CDATA[<p dir="auto">Hi, thanks for guiding me in the right direction.<br />
I had an error in the placement of the script.</p>
<p dir="auto">Now I have verified that it works.<br />
I will then delete the sleep 60 command and the output to the file, I had time to find out if the necessary services are really turned off.</p>
<p dir="auto">so my solution was as follows:</p>
<p dir="auto">file creation</p>
<pre><code>sudo nano /usr/lib/systemd/system-sleep/wakeup.sh
</code></pre>
<p dir="auto">the contents of the file</p>
<pre><code>#!/bin/sh

case $1/$2 in
pre/*)
echo "zastavuji domoticz......"
service domoticz.sh stop &gt;&gt; /home/meteo/vystup_off.txt
sleep 60
;;
post/*)
echo "spouštím domoticz......"
service domoticz.sh start &gt;&gt; /home/meteo/vystup_on.txt
sleep 0
;;
esac
</code></pre>
<p dir="auto">permission settings</p>
<pre><code>sudo chmod a+x /usr/lib/systemd/system-sleep/wakeup.sh
</code></pre>
<p dir="auto">once again thank you very much.</p>
<p dir="auto">my next goal : Control MM Using systemd/systemctl<br />
PM2 is not working correctly on Ubuntu 24 and I need to have MM as a service.<br />
so far I’m using <a href="http://mm.sh" target="_blank" rel="noopener noreferrer nofollow ugc">mm.sh</a> after startup.</p>
<pre><code>cd ./MagicMirror
DISPLAY=:0 npm start
read;
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/120868</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120868</guid><dc:creator><![CDATA[majsoft]]></dc:creator><pubDate>Mon, 28 Oct 2024 10:48:21 GMT</pubDate></item><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Sat, 26 Oct 2024 22:16:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/majsoft" aria-label="Profile: majsoft">@<bdi>majsoft</bdi></a> ok, here is the doc I found</p>
<p dir="auto">Suggesting to read this manual page:</p>
<p dir="auto"><a href="https://www.man7.org/linux/man-pages/man8/systemd-sleep.8.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://www.man7.org/linux/man-pages/man8/systemd-sleep.8.html</a></p>
<p dir="auto">Especially this section:</p>
<p dir="auto">Immediately before entering system suspend and/or hibernation<br />
systemd-suspend.service (and the other mentioned units, respectively)</p>
<p dir="auto">will run all executables</p>
<p dir="auto">in <em><strong>/usr/lib/systemd/system-sleep/</strong></em> and pass <em><strong>two</strong></em> arguments to them.</p>
<p dir="auto">The first argument will be “pre”,<br />
the second either “suspend”, “hibernate”, “hybrid-sleep”, or “suspend-then-hibernate”</p>
<p dir="auto">depending on the chosen action. An environment variable called “SYSTEMD_SLEEP_ACTION” will be set and contain the sleep action that is processing. This is primarily helpful for “suspend-then-hibernate” where the value of the variable will be “suspend”, “hibernate”, or “suspend-after-failed-hibernate” in cases where hibernation has failed.</p>
<p dir="auto">Immediately after leaving system suspend and/or hibernation the same executables are run, but the first argument is now <em><strong>“post”.</strong></em></p>
<p dir="auto">All executables in this directory are executed in parallel, and execution of the action is not continued until all executables have finished.</p>
<hr />
<p dir="auto">so your script should go in that folder… and of course be set with permissions to be executable by root</p>
<p dir="auto">see the chmod and chgrp commands</p>
<p dir="auto">the permissions are in three sections<br />
for the current user<br />
for the a group (the user might be in)<br />
for all other</p>
<p dir="auto">when you do ls -laF somefile (i picked a text file)<br />
-rw-rw-r-- 1 sam sam 8087 Oct 26 08:59 somefile.txt<br />
the permissions are<br />
user rw-  (rear/write but not executable<br />
group rw-       (read/write but not executable)<br />
and all others r--  (read only)<br />
that is 3 bits each +1 so 10 bits of permission<br />
usually represented by a number<br />
in this case 664<br />
7 is all bits on 111<br />
0 is all bits off 000<br />
chmod has shortcuts too  chmod +x make executable for all sections<br />
chmod -w makes it not writeble for all</p>
<p dir="auto">so if you want to make a file  read/write and executable by bob, read only for anyone in group testers, and NO access for anyone else (other)<br />
740 bob testers<br />
chown  and chgrp  are used to set the owner and group</p>
<p dir="auto">in linux most commands have help with the --help  parameter chown --help<br />
and most have a manual page with more text<br />
the get the manual page, type<br />
man command_name<br />
like<br />
man chown</p>
]]></description><link>https://forum.magicmirror.builders/post/120844</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120844</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sat, 26 Oct 2024 22:16:38 GMT</pubDate></item><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Sat, 26 Oct 2024 20:22:20 GMT]]></title><description><![CDATA[<p dir="auto">I can’t get the script to run itself, there are tutorials everywhere but none of them worked for me. I have to study further.</p>
]]></description><link>https://forum.magicmirror.builders/post/120842</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120842</guid><dc:creator><![CDATA[majsoft]]></dc:creator><pubDate>Sat, 26 Oct 2024 20:22:20 GMT</pubDate></item><item><title><![CDATA[Reply to ubuntu - run the script before sleeping and after waking up the PC on Tue, 22 Oct 2024 22:37:15 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/majsoft" aria-label="Profile: majsoft">@<bdi>majsoft</bdi></a></p>
<p dir="auto">what does this</p>
<pre><code>PC goes to sleep and then wakes up with PIR (ESP8266).
</code></pre>
<p dir="auto">is there a MagicMirror module?  or??</p>
<p dir="auto">whatever does that is where you want to call your script to do the server shutdown and startup<br />
exactly what you do on the console.</p>
<p dir="auto">if this requires sudo authority, you can add your userid to the /etc/sudoers file<br />
to not prompt for your password<br />
(google search)</p>
]]></description><link>https://forum.magicmirror.builders/post/120770</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/120770</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 22 Oct 2024 22:37:15 GMT</pubDate></item></channel></rss>