Enabling the power button for shut down.


Forum: Other Help Topics
Topic: Enabling the power button for shut down.
started by: lester67

Posted by lester67 on Dec. 08 2006,03:37
I'm installing DSL 3.0 on a Dell CP laptop.  I'd like for it to recognize when the power button has been hit, so it can initiate its own shutdown.

Is there anyway to make that happen?

(Dell specs are located here: < http://support.dell.com/support/edocs/systems/pmojav/specs.htm > )

Thanks in advance!
Lester

Posted by ^thehatsrule^ on Dec. 08 2006,13:49
Something to do with apm/acpi (power management)...?
Posted by Juanito on Dec. 08 2006,14:46
If your machine is acpi compliant, you can install the acpid daemon and write a simple script to call "exitcheck.sh shutdown" when the powerbutton is pressed momentarily
Posted by lester67 on Dec. 11 2006,00:50
Excellent.  Forgot to add: I'm a Linux idiot.  How, exactly, would that script look? :-)
Posted by lester67 on Dec. 11 2006,01:46
Quick update: during boot it reports...

"ACPI BIOS Found.  Activating Modules: ac battery button fan processor thermal"

Not sure what "button" means, but it looks like ACPI is on there.  I just need a way to throw the switch. (Pardon the metaphor.)

Posted by Juanito on Dec. 11 2006,04:52
You need to install the acpid daemon - either by "apt-get install acpid" or by downloading the deb package and "dpkg -i /path-to-file/acpid_blah_blah.deb" or by downloading and installing the acpid .bz.tar from the acpid project site.

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 both powerbtn files 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
# or /usr/local/bin/exitcheck.sh reboot

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

Powered by Ikonboard 3.1.2a
Ikonboard © 2001 Jarvis Entertainment Group, Inc.