|
Execute script before suspend/after resume using pm-utils in Ubuntu Hardy |
|
|
|
|
Written by Han
|
|
Oct 07, 2008 at 11:34 AM |
|
Suspend/resume works flawless on my Thinkpad T61p running Ubuntu Hardy 64-bit after I did some minor changes described in this article, in fact suspend-to-ram/resume works so well that I only reboot the system once every 2-3 weeks. Using suspend-to-ram/resume saves a lot of hassles but it could also cause some additional problems. For example, I have a samba file server in the local network at home, if I mount the shared directory on my laptop, suspend, and then resume when I get to office, the system can no longer find the file server and it would cause some problem. In order to solve this problem, I need to setup the laptop so that it would automatically unmount the samba directory before the machine goes into suspend.
1) Where should your put your script In Ubuntu by default uses the pm-utils package to handle suspend, it provides ways to insert scripts particularly to be run before suspend/after resume. In previous versions of Ubuntu, the scripts in /etc/acpi/suspend.d would be executed before suspend, however in Hardy this trick doesn't work. The README file in pm-utils doesn't provide much help since it is well out of date. With a more detailed investigation, I finally figured out that you need to put /usr/lib/pm-utils/sleep.d in Ubuntu Hardy.
2) When a script in /usr/lib/pm-utils/sleep.d is called, it is called in the format of "/usr/lib/pm-utils/sleep.d/YOURSCRIPT [state]", where the argument [state] can be suspend|resume|hibernate|thaw. Here is an example script:
#!/bin/sh
##
## suspend-example.sh
##
case $1 in
suspend)
## COMMANDS THAT YOU WISH TO RUN BEFORE SUSPEND
COMMAND1
;;
resume)
## COMMANDS THAT YOU WISH TO RUN AFTER RESUME
COMMAND2
;;
hibernate)
## COMMANDS THAT YOU WISH TO RUN BEFORE HIBERNATE
COMMAND3
;;
thaw)
## COMMANDS THAT YOU WISH TO RUN AFTER RESUME FROM SUSPEND TO DISK
COMMAND4
;;
esac
|
Comment by Anonymous on 2009-11-28 18:51:30 Nice, works like a charm :-) I'm using it for a wireless restart script. The latter is using wpa_supplicant so it's all command line and no GUI like the network-manager. |
|
|
Last Updated ( Oct 07, 2008 at 11:57 AM )
|