[http://acpid.sourceforge.net/ acpid] is a flexible and extensible daemon for delivering [[ACPI modules|ACPI events]]. It listens on {{ic|/proc/acpi/event}} and when an event occurs, executes programs to handle the event. These events are triggered by certain actions, such as:

[http://acpid.sourceforge.net/ acpid] is a flexible and extensible daemon for delivering [[ACPI modules|ACPI events]]. It listens on {{ic|/proc/acpi/event}} and when an event occurs, executes programs to handle the event. These events are triggered by certain actions, such as:

* Pressing special keys, including the Power/Sleep/Suspend button

* Pressing special keys, including the Power/Sleep/Suspend button

Line 9:

Line 15:

* (Un)Plugging an AC power adapter from a notebook

* (Un)Plugging an AC power adapter from a notebook

* (Un)Plugging phone jack etc.

* (Un)Plugging phone jack etc.

−

−

acpid can be used by itself, or combined with a more robust system such as [[pm-utils]] and [[CPU Frequency Scaling|cpufrequtils]] to provide a more complete power management solution.

{{Note|

{{Note|

Line 20:

Line 24:

[[pacman|Install]] the {{Pkg|acpid}} package, available in the [[Official Repositories|official repositories]].

[[pacman|Install]] the {{Pkg|acpid}} package, available in the [[Official Repositories|official repositories]].

−

To have it start on boot :

+

To have ''acpid'' started on boot, [[systemd#Using units|enable]] {{ic|acpid.service}}.

−

* if you're using [[systemd]], run {{ic|systemctl enable acpid}} ;

−

* if you're using [[rc.conf|initscripts]], edit {{ic|/etc/rc.conf}} as root and add {{ic|acpid}} to the [[rc.conf#Daemons|DAEMONS array]].

== Configuration ==

== Configuration ==

Line 94:

Line 96:

==Tips and tricks==

==Tips and tricks==

{{Tip|Some of actions, described here, such as Wi-Fi toggle and backlight control, may already be managed directly by driver. You should consult documentation of corresponding kernel modules, when this is the case.}}

{{Tip|Some of actions, described here, such as Wi-Fi toggle and backlight control, may already be managed directly by driver. You should consult documentation of corresponding kernel modules, when this is the case.}}

−

−

===Extending acpid with pm-utils===

−

−

Although {{Pkg|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 common fixes for stubborn hardware and drivers (e.g. fglrx module). pm-utils provides two scripts, {{ic|pm-suspend}} and {{ic|pm-hibernate}}, both of which can be inserted as events into acpid. For more information, check the [[pm-utils]] wiki.

===Example Events===

===Example Events===

Line 121:

Line 119:

close)

close)

#echo "LID switched!">/dev/tty5

#echo "LID switched!">/dev/tty5

−

/usr/sbin/pm-suspend &

+

/usr/bin/pm-suspend &

DISPLAY=:0.0 su -c - username /usr/bin/slimlock

DISPLAY=:0.0 su -c - username /usr/bin/slimlock

−

;;

−

−

Execute {{ic|pm-suspend}} when the sleep button is pressed:

−

−

button/sleep)

−

case "$2" in

−

SBTN)

−

#echo -n mem >/sys/power/state

−

/usr/sbin/pm-suspend

;;

;;

Line 222:

Line 211:

case `cat $rf/state` in

case `cat $rf/state` in

−

0) echo 1 >$rf/state && systemctl start net-auto-wireless;;

+

0) echo 1 >$rf/state;;

−

1) systemctl stop net-auto-wireless && echo 0 >$rf/state;;

+

1) echo 0 >$rf/state;;

esac

esac

</nowiki>}}

</nowiki>}}

Line 229:

Line 218:

=== Laptop Monitor Power Off ===

=== Laptop Monitor Power Off ===

−

Adapted from the [http://en.gentoo-wiki.com/wiki/ACPI/Configuration Gentoo Wiki] comes this little gem. Add this to the bottom of {{ic|/etc/acpi/actions/lm_lid.sh}} or to the ''button/lid'' section {{ic|/etc/acpi/handler.sh}}. This will turn off the LCD back-light when the lid is closed, and restart when the lid is opened.

+

Adapted from the [http://en.gentoo-wiki.com/wiki/ACPI/Configuration Gentoo Wiki] comes this little gem. Add this to the ''button/lid'' section of {{ic|/etc/acpi/handler.sh}}. This will turn off the LCD back-light when the lid is closed, and restart when the lid is opened.

On newer systems using systemd, X11 logins are no longer necessarily displayed in {{ic|who}}, so the {{ic|getuser}} function above does not work. An alternative is to use {{ic|loginctl}} to obtain the required information, e.g. using [https://github.com/rephorm/xuserrun xuserrun].

+

+

=== ACPI hotkey ===

+

You can either directly edit {{ic|/etc/acpi/handler.sh}}, to react to the ACPI events, or you can point it to another shell script (i.e. {{ic|/etc/acpi/hotkeys.sh}})

−

On newer systems using systemd, X11 logins are no longer necessarily displayed in {{ic|who}}, so the {{ic|getuser}} function above does not work. An alternative is to use {{ic|loginctl}} to obtain the required information, e.g. using [https://github.com/rephorm/xuserrun xuserrun].

+

Under the section

+

case "$1" in

+

+

Add the following lines:

+

hkey)

+

case "$4" in

+

00000b31)

+

echo "PreviousButton pressed!"

+

exailectl p

+

;;

+

00000b32)

+

echo "NextButton pressed!"

+

exailectl n

+

;;

+

00000b33)

+

echo "Play/PauseButton pressed!"

+

exailectl pp

+

echo "executed.."

+

;;

+

00000b30)

+

echo "StopButton pressed!"

+

exailectl s

+

;;

+

*)

+

echo "Hotkey Else: $4"

+

;;

+

esac

+

;;

+

+

The '00000b31' etc. values are the response received from acpi_listen.

+

+

Also, the exailectl script is a brief shell script I created for controlling Exaile music player. As the ACPID is run from root, you will need to use

+

sudo -u (username) exaile

+

for example, otherwise it will not detect your user-level program and recreate another.

desktop environments, such as GNOME, systemd login manager and some extra key handling daemons may implement own event handling schemes, independent of acpid. Running more than one system at the same time may lead to unexpected behaviour, such as suspending two times in a row after one sleep button press. You should be aware of this and only activate desirable handlers.

Since by default the script provided by acpid, /etc/acpi/handler.sh, will override your desktop environment's power button functionality, you most likely want to change acpid's power off routine to avoid shutting down the system suddenly when you press the power button (see instructions below).

Installation

Configuration

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, which is executed after any ACPI events are detected (as determined by /etc/acpi/events/anything).

The following is a brief example of 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 (suspend) state:

The output of acpi_listen is sent to /etc/acpi/handler.sh as $1, $2 , $3 & $4 parameters.
Example:

$1 power/button
$2 PBTN
$3 00000000
$4 00000b31

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 /etc/acpi/handler.sh file to execute a variety of commands depending on which event is triggered. See the Tips & Tricks section below for other commonly used commands.

Alternative configuration

By default, all ACPI events are passed through the /etc/acpi/handler.sh script. This is due to the ruleset outlined in /etc/acpi/events/anything:

While this works just fine as it is, some users may prefer to define event rules and actions in their own self-contained scripts. The following is an example of how to use an individual event file and corresponding action script:

Using this method, it is easy to create any number of individual event/action scripts.

Tips and tricks

Tip: Some of actions, described here, such as Wi-Fi toggle and backlight control, may already be managed directly by driver. You should consult documentation of corresponding kernel modules, when this is the case.

Example Events

The following are examples of events that can be used in the /etc/acpi/handler.sh script. These examples should be modified so that they apply your specific environment e.g. changing the event variable names interpreted by acpi_listen.

To lock the screen with xscreensaver when closing the laptop lid:

button/lid)
case $3 in
close)
# The lock command need to be run as the user who owns the xscreensaver process and not as root.
# See: man xscreensaver-command. $xs will have the value of the user owning the process, if any.
xs=$(ps -C xscreensaver -o user=)
if test $xs; then su $xs -c "xscreensaver-command -lock"; fi
;;

To suspend the system and lock the screen using slimlock when the lid is closed:

Laptop Monitor Power Off

Adapted from the Gentoo Wiki comes this little gem. Add this to the button/lid section of /etc/acpi/handler.sh. This will turn off the LCD back-light when the lid is closed, and restart when the lid is opened.

If you would like to increase/decrease brightness or anything dependent on X, you should specify the X display as well as the MIT magic cookie file (via XAUTHORITY). The last is a security credential providing read and write access to the X server, display, and any input devices.

With certain combinations of Xorg and stubborn hardware, xset dpms force off only blanks the display leaving the backlight turned on. This can be fixed using vbetool from the official repositories. Change the LCD section to:

On newer systems using systemd, X11 logins are no longer necessarily displayed in who, so the getuser function above does not work. An alternative is to use loginctl to obtain the required information, e.g. using xuserrun.

ACPI hotkey

You can either directly edit /etc/acpi/handler.sh, to react to the ACPI events, or you can point it to another shell script (i.e. /etc/acpi/hotkeys.sh)