LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Power button map to shutdown command (https://www.linuxquestions.org/questions/linux-hardware-18/power-button-map-to-shutdown-command-542856/)

sadarax 04-03-2007 12:21 AM

(SOLVED) Power button map to shutdown command
 
I have a computer I would like to be able to turn off by merely pressing the power button, and having Linux respond by initiating a proper shutdown command and sequence. Is this possible to do and how would I do it?

The System Spec's:
Quote:

MotherBoard: Abit Kt7 Raid
CPU: AMD Athlon T-Bird 1200 MHz
RAM: SD-PC-133 512MB
Video Card: nVidia Riva TNT2 32MB
Sound: Sound Blaster Live!
TV Capture Card: Hauppauge PVR-150
Distro: KnoppMyth:
* Release 5 E50
* MythTV: 0.20
Desktop Environment: FluxBox
Kernel: 2.6.18-chw-13

Muraii 04-03-2007 12:40 AM

Use ACPI
 
Hi there,

I was curious about this, too, so trying to figure out how to help you prompted me to learn a bit. Read this relevant LQ post and answer. I have also found the Gentoo wiki to be extremely helpful no matter what distro you run (I run Slackware). I found an article describing the details that should be applicable here.

Good luck, and let us know if this helped.

Daniel

sadarax 04-03-2007 01:35 AM

Thanks a ton Murali. The Gentoo wiki was especially helpful. I managed to get everything working. Here is a quick tutorial for what I did on my Debian based system.

1) Check to see that the button is registered:

dmesg | grep '^ACPI:'

If you get any output, you have ACPI compiled in

2) Registering the power button as an ACPI event

cat /var/log/dmesg | grep '^ACPI: Power Button'

If you get output, then your power button is registered. If not, then you'll need to either a) recompile the kernel with button registration engaged, or b) load the button module.

3) Load the button module

Ensure that you're kernel has button support available. Find the 'button.ko' file.

Load the button module to test for errors:
insmod /location/of/button.ko
lsmod | grep button

If you receive no errors and lsmod returns information, then the module has been successfully inserted.

4) Load 'button' module on startup

Ensure that you have the 'button' kernel module loaded/loading on system startup. In Debian, you do this by adding to the /etc/modules.

5) Make sure ACPID is on the system

apt-get install acpid

If the installation does not automatically add startup and shutdown links in the /etc/rc*.d directores, you should manually add them.

6) ACPI-Events

Go to the directory /etc/acpi/events, if it does not exist, create it.
Create the file 'power' with:
vim /etc/acpi/events/power

Add this to 'power'
event=button/power.*
action=/etc/acpi/onButtonPress-Power.sh

7) An example of /etc/acpi/onButtonPress-Power.sh

#!/bin/sh
# /etc/acpi/onButtonPress-Power.sh
#Shutdown when the power button is pressed

logger "Power button pressed -- shutting system down"
/sbin/shutdown -h now

8) Make executable. Don't forget!

chmod 750 /etc/acpi/onButtonPress-Power.sh

Muraii 04-04-2007 08:35 AM

sadarax,

Glad to hear it! I've been making use of the community for help for a long time, it seems; it's nice to have been able to help. And I've learned something myself.

Daniel


All times are GMT -5. The time now is 06:30 PM.