These are my scripts:
/etc/acpi/acpi_handler.sh:
#!/bin/sh
# Default acpi script that takes an entry for all actions
IFS=${IFS}/
set $@
LIDSTATE=$(/bin/sed -ne "/state:/{s/^state:[ ]*\([a-zA-Z]*\)$/\1/p;q}" \
/proc/acpi/button/lid/LID/state)
case "$1" in
button)
case "$2" in
power)
if [ "$LIDSTATE" == "open" ]; then
/usr/sbin/presusp
hibernate -F /etc/hibernate/ram.conf
elif [ "$LIDSTATE" == "closed" ]; then
hibernate -F /etc/hibernate/ususpend-ram.conf
fi
;;
lid)
if [ "$LIDSTATE" == "closed" ]; then
/usr/sbin/presusp
hibernate -F /etc/hibernate/ram.conf
elif [ "$LIDSTATE" == "open" ]; then
hibernate -F /etc/hibernate/ususpend-ram.conf
fi
;;
*) logger "ACPI action $2 is not defined"
;;
esac
;;
*)
logger "ACPI group $1 / action $2 is not defined"
;;
esac
acpi_handler.sh will suspend to ram if the lid is closed or if the power button is pushed.
/usr/sbin/presusp is simply a script that has commands in that should be used before suspending, such as unmounting all external storage devices, killing wpa_supplicant and dhcpcd, removing modules:
#!/bin/bash
execute_commands() {
killall dhcpcd
killall wpa_supplicant
vlh-umount
umount /mnt/shared
/sbin/ifconfig eth1 down
/sbin/ifconfig eth0 down
/sbin/ifconfig wlan0 down
/sbin/rmmod zd1211rw
/sbin/rmmod ndiswrapper
/sbin/rmmod 8139too
}
Since the acpid daemon runs this as root, there is no need to use sudo. But to let user suspend, I did the following:
1 - Create a new group called hibernate.
Open /etc/group and create a new group called "hibernate" and then add the usernames you want to be part of that group. Here is an example:
hibernate::44:easuter
2 - Create entries in /etc/sudoers to allow users belonging to that group to use the scripts without passwords (make a backup of /etc/sudoers before doing this!):
visudo
Now enter this text:
#Let users that belong to the "hibernate" group use suspend/hibernate commands
#without entering the root password:
Cmnd_Alias HIBERNATE=/usr/sbin/hibernate
Cmnd_Alias PRESUSP=/usr/sbin/presusp
%hibernate ALL=NOPASSWD:HIBERNATE,PRESUSP
Save the file and that should be it!
To run the hibernate script for a suspend to disk, do:
sudo /usr/sbin/hibernate
If you want to suspend to ram, then do:
sudo /usr/sbin/hibernate -F /etc/hibernate/ram.conf
You can also run the pre-suspend script before any of these commands of course.
Hope this is useful
