Difference between revisions of "How to configure acpid"

From ThinkWiki
Jump to: navigation, search
Line 1: Line 1:
Basically, acpid just executes scripts residing in <tt>/etc/acpi/actions</tt>. Which script to launch at which event is configured in several files in <tt>/etc/acpi/events</tt>. {{cmd|man acpid}} holds detailed information on how to configure acpid.
+
Basically, acpid just executes scripts residing in {{path|/etc/acpi/actions}}. Which script to launch at which event is configured in several files in {{path|/etc/acpi/events}}. {{cmd|man acpid}} holds detailed information on how to configure acpid.
  
The [[ibm-acpi]] package includes example scripts in the <tt>config</tt> folder inside the tarball. They are a good starting point to adjust them to your needs. You also might want to have a look at the [[Configs#ACPI | ACPI section of the Configs page]] or the [[:Category:Scripts|Scripts]] repository. And you can find information about the event strings [[ibm-acpi]] generates for certain keys at the [[How to get special keys to work#ibm-acpi_events | Special Keys HOWTO]].
+
The [[ibm-acpi]] package includes example scripts in the {{path|config}} folder inside the tarball. They are a good starting point to adjust them to your needs. You also might want to have a look at the [[Configs#ACPI | ACPI section of the Configs page]] or the [[:Category:Scripts|Scripts]] repository. And you can find information about the event strings [[ibm-acpi]] generates for certain keys at the [[How to get special keys to work#ibm-acpi_events | Special Keys HOWTO]].
  
 
==Example: go to sleep on lid close==
 
==Example: go to sleep on lid close==
Line 9: Line 9:
 
of going to sleep and resuming.
 
of going to sleep and resuming.
  
The event script needs to be created within <tt>/etc/acpi/events</tt> and can have any name you like.
+
The event script needs to be created within {{path|/etc/acpi/events}} and can have any name you like.
 
In this case we call it lid because it will trigger the lid event. Do {{cmdroot|vi /etc/acpi/events/lid}} and make it look like this:
 
In this case we call it lid because it will trigger the lid event. Do {{cmdroot|vi /etc/acpi/events/lid}} and make it look like this:
 
  event=button/lid
 
  event=button/lid
Line 16: Line 16:
 
The "event" line is a regular expression specifying the events we're
 
The "event" line is a regular expression specifying the events we're
 
interested in. You can determine what the event strings are from looking at
 
interested in. You can determine what the event strings are from looking at
<tt>/var/log/acpid</tt> after trying to suspend, close the lid, etc. .
+
{{path|/var/log/acpid}} after trying to suspend, close the lid, etc. .
 
You can find information about the event strings [[ibm-acpi]] generates for certain keys at the [[How to get special keys to work#ibm-acpi_events | Special Keys HOWTO]].
 
You can find information about the event strings [[ibm-acpi]] generates for certain keys at the [[How to get special keys to work#ibm-acpi_events | Special Keys HOWTO]].
  
 
The "action" line is the command to be executed when these events are
 
The "action" line is the command to be executed when these events are
dispatched. In this example we call the <tt>sleep.sh</tt> script residing in <tt>/etc/acpi/actions</tt> and pass the event description text using the %e placeholder.
+
dispatched. In this example we call the {{path|sleep.sh}} script residing in {{path|/etc/acpi/actions}} and pass the event description text using the %e placeholder.
  
{{NOTE|To make your changes take effect after adding or modifying the events files you must do a <tt>'''kill -SIGHUP `pidof acpid`'''</tt>}}.
+
{{NOTE|To make your changes take effect after adding or modifying the events files you must do a <tt>kill -SIGHUP `pidof acpid`</tt>}}.
  
Our example <tt>/etc/acpi/actions/sleep.sh</tt> script looks as follows:
+
Our example {{path|/etc/acpi/actions/sleep.sh}} script looks as follows:
  
 
  #!/bin/sh
 
  #!/bin/sh
Line 63: Line 63:
 
To circumvent those we remove the USB driver prior to suspend and reload it afterwards.
 
To circumvent those we remove the USB driver prior to suspend and reload it afterwards.
  
Note that the <code>echo -n "mem" > /sys/power/state
+
Note that the {{cmdroot|echo -n "mem" > /sys/power/state}} line does not return until we are revived. So there is
</code> line does not return until we are revived. So there is
+
only one event generated and there is no need to check the state of anything.
only one event generated and there is no need to check the state of
 
anything.
 
  
 
The console switching code in this script is a special solution for
 
The console switching code in this script is a special solution for
Line 76: Line 74:
  
  
[[Category:570]] [[Category:570E]] [[Category:A20m]] [[Category:A20p]] [[Category:A20m]] [[Category:A20p]] [[Category:A21e]] [[Category:A21m]] [[Category:A21p]] [[Category:A22e]] [[Category:A22m]] [[Category:A22p]] [[Category:G40]] [[Category:G41]] [[Category:R30]] [[Category:R31]] [[Category:R32]] [[Category:R40]] [[Category:R40e]] [[Category:R50]] [[Category:R50p]] [[Category:R51]] [[Category:R52]] [[Category:T20]] [[Category:T21]] [[Category:T22]] [[Category:T23]] [[Category:T30]] [[Category:T40]] [[Category:T40p]] [[Category:T41]] [[Category:T41p]] [[Category:T42]] [[Category:T42p]] [[Category:T43]] [[Category:T43p]] [[Category:X20]] [[Category:X21]] [[Category:X22]] [[Category:X23]] [[Category:X24]] [[Category:X30]] [[Category:X31]] [[Category:X32]] [[Category:X40]] [[Category:X41]]
+
[[Category:570]] [[Category:570E]] [[Category:A20m]] [[Category:A20p]] [[Category:A20m]] [[Category:A20p]] [[Category:A21e]] [[Category:A21m]] [[Category:A21p]] [[Category:A22e]] [[Category:A22m]] [[Category:A22p]] [[Category:G40]] [[Category:G41]] [[Category:R30]] [[Category:R31]] [[Category:R32]] [[Category:R40]] [[Category:R40e]] [[Category:R50]] [[Category:R50p]] [[Category:R51]] [[Category:R52]] [[Category:T20]] [[Category:T21]] [[Category:T22]] [[Category:T23]] [[Category:T30]] [[Category:T40]] [[Category:T40p]] [[Category:T41]] [[Category:T41p]] [[Category:T42]] [[Category:T42p]] [[Category:T43]] [[Category:T43p]] [[Category:X20]] [[Category:X21]] [[Category:X22]] [[Category:X23]] [[Category:X24]] [[Category:X30]] [[Category:X31]] [[Category:X32]] [[Category:X40]] [[Category:X41]] [[Category:X41 Tablet]]

Revision as of 12:46, 24 July 2005

Basically, acpid just executes scripts residing in /etc/acpi/actions. Which script to launch at which event is configured in several files in /etc/acpi/events. {{{2}}} man acpid holds detailed information on how to configure acpid.

The ibm-acpi package includes example scripts in the config folder inside the tarball. They are a good starting point to adjust them to your needs. You also might want to have a look at the ACPI section of the Configs page or the Scripts repository. And you can find information about the event strings ibm-acpi generates for certain keys at the Special Keys HOWTO.

Example: go to sleep on lid close

To make the ThinkPad go to sleep when you close the lid, you need to add an event handler for the lid event and an action script that takes care of going to sleep and resuming.

The event script needs to be created within /etc/acpi/events and can have any name you like. In this case we call it lid because it will trigger the lid event. Do # vi /etc/acpi/events/lid and make it look like this:

event=button/lid
action=/etc/acpi/actions/sleep.sh %e

The "event" line is a regular expression specifying the events we're interested in. You can determine what the event strings are from looking at /var/log/acpid after trying to suspend, close the lid, etc. . You can find information about the event strings ibm-acpi generates for certain keys at the Special Keys HOWTO.

The "action" line is the command to be executed when these events are dispatched. In this example we call the sleep.sh script residing in /etc/acpi/actions and pass the event description text using the %e placeholder.

NOTE!
To make your changes take effect after adding or modifying the events files you must do a kill -SIGHUP `pidof acpid`

.

Our example /etc/acpi/actions/sleep.sh script looks as follows:

#!/bin/sh

# if launched through a lid event and lid is open, do nothing
echo "$1" | grep "button/lid" && grep -q open /proc/acpi/button/lid/LID/state && exit 0

# remove USB 1.1 driver
rmmod uhci_hcd
 
# sync filesystem and clock
sync
/sbin/hwclock --systohc

# switch to console
FGCONSOLE=`fgconsole`
chvt 6
/usr/sbin/radeontool light off

# go to sleep
echo -n "mem" > /sys/power/state

# readjust the clock (it might be off a bit after suspend)
/sbin/hwclock --adjust
/sbin/hwclock --hctosys

# reload USB 1.1 driver
modprobe uhci_hcd

# turn on the backlight and switch back to X
radeontool light on
chvt $FGCONSOLE

The lid generates an event for both opening and closing thus requiring that we check it's state and only act if it's closed.

There have been problems encountered with the USB devices not working properly after a resume from suspend. To circumvent those we remove the USB driver prior to suspend and reload it afterwards.

Note that the # echo -n "mem" > /sys/power/state line does not return until we are revived. So there is only one event generated and there is no need to check the state of anything.

The console switching code in this script is a special solution for a problem where the backlight doesn't switch off on the T30 and some other models. Before going to sleep, these models switch to console mode which causes the backlight to come back on. So we preemptively switch to console mode and turn off the backlight using radeontool before going to sleep.

NOTE!
If your display doesn't come back on resume, look here.