Suspend/Hibernate/Resume/Thaw - Scripts
I need to run a script on a Suspend/Hibernate and on a Resume/Thaw. Now, I know the place to put the script is /etc/pm/sleep.d/ but this doesn't seem to work for a script requiring access to the network as the network is either already down or not up yet when it runs. Is there another place I need to put my script so it has access to the network before the network is shutdown on a suspend and after the network is up on a resume?
Basically, I just need to send out a UDP broadcast like:
echo -n "Resumed" | socat - udp-datagram:192.168.5.255:5100,broadcast
I'm running ubuntu 11.10.
Re: Suspend/Hibernate/Resume/Thaw - Scripts
Hello and welcome to the forums.
Have a look at the /etc/network/if-up.d directory. These scripts run after the interface comes up.
Re: Suspend/Hibernate/Resume/Thaw - Scripts
Thanks for the reply. I'll give that a try.
What about for a suspend, before the network is brought down?
Re: Suspend/Hibernate/Resume/Thaw - Scripts
Quote:
Originally Posted by
stbluesrul
What about for a suspend, before the network is brought down?
I believe that when the system resumes and the network interface is brought back up, the same scripts in /etc/network/if-up.d will be re-run.
Re: Suspend/Hibernate/Resume/Thaw - Scripts
Ok, the script in /etc/network/if-up.d worked great when it boots up or resumes.
Now I just need to know where to put a script so I can send out a network message that the PC is being Suspended or Hibernated.
Like:
echo -n "Hibernating" | socat - udp-datagram:192.168.5.255:5100,broadcast
I see there are other scripts in /etc/network. I tried /etc/network/if-down.d but that didn't work. Anything else I can try?
Re: Suspend/Hibernate/Resume/Thaw - Scripts
Quote:
Now I just need to know where to put a script so I can send out a network message that the PC is being Suspended or Hibernated.
You could put that in /etc/pm/sleep.d as 01_socat (before the network is taken down). The file should look like:
Code:
case $1 in
suspend|suspend_hybrid|hibernate)
echo -n "Hibernating" | socat - udp-datagram:192.168.5.255:5100,broadcast
;;
resume|thaw)
# Do nothing, handled by /etc/network/if-up.d
;;
esac
Make this file executable.
Re: Suspend/Hibernate/Resume/Thaw - Scripts
This doesn't seem to work as the network is already taken down. I verified that the script is in fact working by just having it create a directory on the desktop but it doesn't send out the broadcast.
echo -n "Hibernating" | socat - udp-datagram:192.168.5.255:5100,broadcast
works correctly when I run it in my other script and through the terminal.
Is there a place that lists exactly what is executed when a hibernate or suspend is done?
Re: Suspend/Hibernate/Resume/Thaw - Scripts
Quote:
Is there a place that lists exactly what is executed when a hibernate or suspend is done?
/var/log/pm-suspend.log will show it. Perhaps you can post the log back for a look:
Code:
pastebinit /var/log/pm-suspend.log
...and post back the link that is generated.
Re: Suspend/Hibernate/Resume/Thaw - Scripts
Here is the link:
http://paste.ubuntu.com/5811441/
I even tried putting the socat command into /usr/lib/pm-utils/sleep.d/000kernel-change as it seems this is the first script that is ran on a suspend but again the network is already down when it executes.
Re: Suspend/Hibernate/Resume/Thaw - Scripts
The earliest place you could put this during a suspend cycle would be before 000kernel-change, say 0000socat. If that doesn't work, then the suspend scripts can't be used because the network is unavailable at the time those scripts are being run.
I came across this code in /etc/NetworkManager/dispatcher.d/01ifupdown:
Code:
# pre-up/pre-down not implemented. See
# https://bugzilla.gnome.org/show_bug.cgi?id=387832
# pre-up)
# export MODE="start"
# export PHASE="pre-up"
# exec run-parts /etc/network/if-pre-up.d
# ;;
# pre-down)
# export MODE="stop"
# export PHASE="pre-down"
# exec run-parts /etc/network/if-down.d
# ;;
This would be ideal for you (pre-down) but as you can see, the code is commented out and if you read the bug report, there is some reluctance to include that functionality.