There are two approaches to choose from:
Using the /lib/systemd/system-sleep/
directory:
Create another script called 00start_my_connection
:
#!/bin/sh
if [ $1 = post ] && [ $2 = suspend ]
then /usr/local/bin/start_my_connection
fi
$1
is "post" on resume/thaw and "pre" otherwise. In either case, $2
contains either "suspend", "hibernate", or "hybrid-sleep". If you want the script to also run on thaw from hibernation, leave out && [ $2 = suspend ]
.
Ensure this script is executable by using chmod a+x 00start_my_connection
Move this script into /lib/systemd/system-sleep/
using
sudo mv 00start_my_connection /lib/systemd/system-sleep/
Using service files:
Create the file /etc/systemd/system/start_my_connection.service
:
[Unit]
Description=Run start_my_connection
After=suspend.target
#After=hibernate.target
#After=hybrid-sleep.target
[Service]
ExecStart=/usr/local/bin/start_my_connection
[Install]
WantedBy=suspend.target
#WantedBy=hibernate.target
#WantedBy=hybrid-sleep.target
Uncomment all lines if you also want the script to run on thaw from hibernation. Then install the service file with:
sudo systemctl enable start_my_connection.service
/etc/pm/sleep.d/
, and check what happens. – mikewhatever Aug 15 '15 at 09:42