Read the statement by Michael Teeuw here.
ubuntu - run the script before sleeping and after waking up the PC
-
@majsoft ok, here is the doc I found
Suggesting to read this manual page:
https://www.man7.org/linux/man-pages/man8/systemd-sleep.8.html
Especially this section:
Immediately before entering system suspend and/or hibernation
systemd-suspend.service (and the other mentioned units, respectively)will run all executables
in /usr/lib/systemd/system-sleep/ and pass two arguments to them.
The first argument will be “pre”,
the second either “suspend”, “hibernate”, “hybrid-sleep”, or “suspend-then-hibernate”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.
Immediately after leaving system suspend and/or hibernation the same executables are run, but the first argument is now “post”.
All executables in this directory are executed in parallel, and execution of the action is not continued until all executables have finished.
so your script should go in that folder… and of course be set with permissions to be executable by root
see the chmod and chgrp commands
the permissions are in three sections
for the current user
for the a group (the user might be in)
for all otherwhen you do ls -laF somefile (i picked a text file)
-rw-rw-r-- 1 sam sam 8087 Oct 26 08:59 somefile.txt
the permissions are
user rw- (rear/write but not executable
group rw- (read/write but not executable)
and all others r-- (read only)
that is 3 bits each +1 so 10 bits of permission
usually represented by a number
in this case 664
7 is all bits on 111
0 is all bits off 000
chmod has shortcuts too chmod +x make executable for all sections
chmod -w makes it not writeble for allso 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)
740 bob testers
chown and chgrp are used to set the owner and groupin linux most commands have help with the --help parameter chown --help
and most have a manual page with more text
the get the manual page, type
man command_name
like
man chown -
Hi, thanks for guiding me in the right direction.
I had an error in the placement of the script.Now I have verified that it works.
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.so my solution was as follows:
file creation
sudo nano /usr/lib/systemd/system-sleep/wakeup.sh
the contents of the file
#!/bin/sh case $1/$2 in pre/*) echo "zastavuji domoticz......" service domoticz.sh stop >> /home/meteo/vystup_off.txt sleep 60 ;; post/*) echo "spouštím domoticz......" service domoticz.sh start >> /home/meteo/vystup_on.txt sleep 0 ;; esac
permission settings
sudo chmod a+x /usr/lib/systemd/system-sleep/wakeup.sh
once again thank you very much.
my next goal : Control MM Using systemd/systemctl
PM2 is not working correctly on Ubuntu 24 and I need to have MM as a service.
so far I’m using mm.sh after startup.cd ./MagicMirror DISPLAY=:0 npm start read;
-
@majsoft cool
pm2 on 24, will review
-
-
@majsoft yeh, that one opened by me!
fairly slow w fixes
-