Power down the system with the power button


Forum: Other Help Topics
Topic: Power down the system with the power button
started by: salvajef

Posted by salvajef on Nov. 08 2006,09:52
I want to use my mini linux system without the keyboard and the mouse, so i need to power down it simply pressing the power button. I want also that the screen don't enter in standby mode after a few minutes. It's possible ?
Posted by skaos on Nov. 08 2006,12:46
I think you can use the xset command to avoid screen blanking, you could try this (not quite sure if it's correct): xset s 0
Posted by Juanito on Nov. 08 2006,15:32
I guess that if your PC is acpi compatible, you could load the acpi modules, load acpid and then use the acpid powerbutton event to run a script.

I don't know where it is, but you could probably call the same script that is called by right clicking on the desktop and chosing "shutdown"

Posted by salvajef on Nov. 14 2006,19:36
My pc is acpi compatible, but i don't know how can i set these information.
At the moment i put in .xintrc file the xset 0 command ... but i think there's a more useful way to do that.

How can i disable the screensaver definitively and set the powerdown button the shootdown script ?

Posted by Juanito on Nov. 15 2006,05:35
I guess the first step would be to verify that your system will work with acpi.

Note that you may need to add "apm=off" and/or "acpi=force" to your syslinux.cfg file to encourage DSL to work with acpi.

Once booted, try to "modprobe" the acpi modules "thermal", "processor", "fan", "button", "battery" & "ac".

If the above works, then try "apt-get install acpid"

If all of the above works, you should be in good shape to have acpid detect a "button" event and run the powerdown script of your choice.

The /share/doc/acpid readme files or the /share/man/acpid files installed with acpid may give some explanation on how to set-up acpi events/scripts. If not, you could try a Google search on acpid and the name of your laptop - in my case this gave several links to explanations on how various people set up their system to work with acpi.

Posted by Juanito on Nov. 15 2006,12:26
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

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