From ArchWiki
Revision as of 09:19, 11 July 2008 by ST.x (Talk | contribs) (incorrect folder)

Jump to: navigation, search


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

acpid can be used by itself, or combined with a more robust system such as Pm-utils and Cpufrequtils to provide a more complete power management solution.


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/ 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.

		case "$2" in
			SLPB) echo -n mem >/sys/power/state ;;
			*)    logger "ACPI action undefined: $2" ;;

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/ 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 file to execute a variety of commands depending on which event is triggered. See the Tips & Tricks section below for more sample commands.

Alternative Configuration

Editing a file like that is annoying. And pacman will probably overwrite it at some point. acpid, thankfully, gives us another option.

Take a look at /etc/acpi/events/anything. This file passes ANY event to the script. We will use this as our template. Here's a better version of the above:

In the file /etc/acpi/events/sleep-button we'll put:

event=button sleep.*
action=/usr/lib/acpi/ "%e"

And in /usr/lib/acpi/

case "$2" in
   SLPB) echo -n mem >/sys/power/state ;;
    *)    logger "ACPI action undefined: $2" ;;

Tips & Tricks

Laptop Monitor Power Off

From "AM088" on the gentoo wiki comes this little gem. Add this to the bottom of your /etc/acpi/actions/ file. This will do nothing but turn your monitor off when you close the lid.

if grep -q open /proc/acpi/button/lid/LID/state
       XAUTHORITY="$( ps -C xinit f|sed 's/.*-auth \(.*\)serverauth.*/\1Xauthority/p' )" /usr/bin/xset -display :0.0 dpms force on
       XAUTHORITY="$( ps -C xinit f| sed -n 's/.*-auth \(.*\)serverauth.*/\1Xauthority/p' )" /usr/bin/xset -display :0.0 dpms force off

This works for me, I manually run startx to begin my xsession.

Sample Events

The following are samples of events that can be dropped into the existing /etc/acpi/ 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:

       #echo "LID switched!">/dev/tty5
       /usr/bin/xscreensaver-command -lock

Execute pm-suspend (from Pm-utils) when the Sleep button is pressed:

	case "$2" in
			#echo -n mem >/sys/power/state

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.

Getting user name at the current display

You can use function getuser

getuser ()
export DISPLAY=`echo $DISPLAY | cut -c -2`
user=`who | grep " $DISPLAY" | awk '{print $1}'`
export XAUTHORITY=/home/$user/.Xauthority
eval $1=$user

to achieve user at the current display. For example when you press the power button and want to shutdown KDE properly you can use this function:

               case "$2" in
                               getuser "$user"
                               echo $user > /dev/tty5
                               su $user -c "dcop ksmserver ksmserver logout 0 2 0"
                       *)    logger "ACPI action undefined $2" ;;

More Resources