Other Help Topics :: Power down the system with the power button



I did some further checking and found that DSL 3.0.1 will automatically load the acpi modules at boot – this being the case, you have to wonder why acpid (which is very small) isn’t included in DSL with a boot option like ssh, ftp, etc.

If you install acpid with apt-get, it also installs a couple of default files to handle power button events. Basically, when the acpi daemon sees an event, it looks in /etc/acpi/events/ for instructions on what to do for that event and then executes the command(s) referenced by the event file. The default files for a power button event are:

/etc/acpi/events/powerbtn
/etc/acpi/powerbtn.sh

The contents of these files are:

# /etc/acpi/events/powerbtn
# This is called when the user presses the power button and calls
# /etc/acpid/powerbtn.sh for further processing.
# Optionally you can specify the placeholder %e. It will pass
# through the whole kernel event message to the program you've
# specified.
# We need to react on "button power.*" and "button/power.*" because
# of kernel changes.

event=button[ /]power
action=/etc/acpi/powerbtn.sh

---------------------------

#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power button has been
# pressed.

/sbin/init 0

By default, acpid creates a log file /var/log/acpid. This log file will allow you to see if your system is reacting to acpi events. Here is an example from my machine.

[Wed Nov 15 12:10:02 2006] starting up
[Wed Nov 15 12:10:02 2006] 1 rule loaded
..
[unplug ac adapter]
..
[Wed Nov 15 12:22:25 2006] received event "ac_adapter AC 00000080 00000000"
[Wed Nov 15 12:22:25 2006] completed event "ac_adapter AC 00000080 00000000"
[Wed Nov 15 12:22:25 2006] received event "battery BAT0 00000080 00000001"
[Wed Nov 15 12:22:25 2006] completed event "battery BAT0 00000080 00000001"
[Wed Nov 15 12:22:25 2006] received event "processor CPU0 00000080 00000007"
[Wed Nov 15 12:22:25 2006] completed event "processor CPU0 00000080 00000007"
..
[press power button briefly - note that the action in powerbtn.sh was commented out so there was no actual shutdown]
..
[Wed Nov 15 12:23:03 2006] received event "button/power PBTN 00000080 00000001"
[Wed Nov 15 12:23:03 2006] executing action "/etc/acpi/powerbtn.sh"
[Wed Nov 15 12:23:03 2006] BEGIN HANDLER MESSAGES
[Wed Nov 15 12:23:03 2006] END HANDLER MESSAGES
[Wed Nov 15 12:23:03 2006] action exited with status 0
[Wed Nov 15 12:23:03 2006] completed event "button/power PBTN 00000080 00000001"

In order to find out how DSL executes a shutdown by right-clicking on the desktop, you can look in /home/dsl/.fluxbox/menu:

  [submenu] (Power Down) {}
      [exec] (Shutdown){ exitcheck.sh shutdown}      
      [exec] (Reboot){ exitcheck.sh reboot}

So, if you modify /etc/acpi/powerbtn.sh to read as follows, save it and add it to .filetools.lst, you can execute a “graceful” shutdown by pressing the power button briefly (if you hold the button too long, the shutdown will not be so graceful..)

#!/bin/sh
# /etc/acpi/poweroff.sh
# Initiates a shutdown when the power putton has been
# pressed.

#/sbin/init 0
/usr/local/bin/exitcheck.sh shutdown

I tried this and it works fine on my Dell Latitude D400


original here.