ACPID is a flexible and extensible daemon for delivering ACPI events. These events are triggered by certain actions, such as:
- Pressing the Power button
- Pressing the Sleep/Suspend button
- Closing a notebook lid
- (Un)Plugging an AC power adapter from a notebook
The acpid package is available from the Current repository:
# pacman -S acpid
Edit /etc/rc.conf as root and add acpid to the DAEMONS array, for example:
DAEMONS=(syslog-ng acpid cpufreq dhcdbd networkmanager @alsa @crond ... )
Note: If you already have hal specified in your DAEMONS, there is no need to add acpid. HAL will automatically detect and load the acpid daemon.
acpid comes with a number of predefined actions for triggered events, such as what should happen when you press the Power button on your machine. By default, these actions are defined in /etc/acpi/handler.sh. The following is a shortened example one such action, in this case when the Sleep Button is pressed acpid runs the command echo -n mem >/sys/power/state which should place the computer into a sleep state.
button/sleep) case "$2" in SLPB) echo -n mem >/sys/power/state ;; *) logger "ACPI action undefined: $2" ;; esac ;;
Unfortunately, not every computer labels the ACPI events in the same way. For example, the Sleep button may be identified on one machine as SLPB and on another as SBTN.
To determine how your buttons or Fn shortcuts are recognized, run the following command from a terminal as root:
# tail -f /var/log/messages.log
Now press the Power button and/or Sleep button (e.g. Fn+Esc) on your machine. The result should look something this:
Aug 29 17:18:31 dublin logger: ACPI action undefined: PBTN Aug 29 17:18:33 dublin logger: ACPI action undefined: SBTN
As you might have noticed, the Sleep button in the sample output is actually recognized as SBTN, rather than the SLPB label specified in the default /etc/acpi/handler.sh. In order for Sleep function to work properly on this machine, we would need to replace SLPB) with SBTN).
Using this information as a base, you can easily customize the handler.sh file to execute a variety of commands depending on which event is triggered. See the Tips & Tricks section below for more sample commands.
Tips & Tricks
The following are samples of events that can be dropped into the existing /etc/acpi/handler.sh script. Bolded text indicates modifications or additions to the default script. As noted above, your event labels may differ so some tweaking may be necessary.
Activate Xscreensaver upon lid closure:
button/lid) #echo "LID switched!">/dev/tty5 /usr/bin/xscreensaver-command -lock ;;
Execute pm-suspend (from Pm-utils) when the Sleep button is pressed:
button/sleep) case "$2" in SBTN) #echo -n mem >/sys/power/state /usr/sbin/pm-suspend ;;
Extending acpid with pm-utils
Although acpid can provide basic suspend2ram out-of-the-box, a more robust system may be desired. Pm-utils provides a very flexible framework for suspend2ram (suspend) and suspend2disk (hibernate) operations, including fixes to stubborn hardware and drivers (e.g. fglrx video). pm-utils primarily consists of 2 scripts, pm-suspend and pm-hibernate, both of which can be inserted as events into acpid. For more information, check the Pm-utils wiki.