Difference between revisions of "Shutdown Pressing Power Button"

From ArchWiki
Jump to: navigation, search
(qdbus doesn't work when run from acpi. Use PowerDevil instead)
Line 2: Line 2:
 
[[Category:HOWTOs (English)]]
 
[[Category:HOWTOs (English)]]
 
{{i18n|Shutdown Pressing Power Button}}
 
{{i18n|Shutdown Pressing Power Button}}
 +
== First solution ==
  
 
If you want to shutdown your system by simply pressing the power button, do the following:
 
If you want to shutdown your system by simply pressing the power button, do the following:
Line 27: Line 28:
 
{{warning|Do not add the acpid daemon to the DAEMON array in "/etc/rc.conf" if hal is already there. You'll get an error message at boot when the computer tries to reload the already running acpi daemon.}}
 
{{warning|Do not add the acpid daemon to the DAEMON array in "/etc/rc.conf" if hal is already there. You'll get an error message at boot when the computer tries to reload the already running acpi daemon.}}
  
If you're using a more sophisticated WM, you should use its own shutdown call, so it'd save its session etc.  
+
If you're using a more sophisticated WM, you should use its own shutdown call, so it'd save its session etc.
 
+
== KDE ==
+
  
 
=== KDE 3 ===
 
=== KDE 3 ===
Line 60: Line 59:
  
 
'''''Note:''' For a more robust solution (If you are facing frequent WM crashes or working on a sacrificial PC for developing or testing your software...), you should take a look at "/usr/src/linux/Documentation/sysrq.txt", which is a kernel facility for yielding you (the user...) the CPU so that it could be used for any '''rescue''' work.''
 
'''''Note:''' For a more robust solution (If you are facing frequent WM crashes or working on a sacrificial PC for developing or testing your software...), you should take a look at "/usr/src/linux/Documentation/sysrq.txt", which is a kernel facility for yielding you (the user...) the CPU so that it could be used for any '''rescue''' work.''
 +
 +
== Second solution ==
 +
(First solution not working for me)
 +
 +
1.Install acpid
 +
2.Add acion for event - change file /etc/acpi/handler.sh:
 +
 +
...
 +
case "$1" in
 +
    button/power)
 +
        #echo "PowerButton pressed!">/dev/tty5
 +
        case "$2" in
 +
            PWRF)  logger "PowerButton pressed: $2"
 +
    /sbin/poweroff;;
 +
            *)      logger "ACPI action undefined: $2" ;;
 +
        esac
 +
        ;;
 +
...
 +
 +
3.Restart hal or acpid if you don't use hal:
 +
# /etc/rc.d/hal restart
 +
or
 +
# /etc/rc.d/acpid restart
  
 
=== TODO ===
 
=== TODO ===
  
 
Add a technique that works regardless of VM (Gnome/KDE/xcfe/openbox/etc). Copy the <tt>/etc/acpi/events/power</tt> script from Ubuntu
 
Add a technique that works regardless of VM (Gnome/KDE/xcfe/openbox/etc). Copy the <tt>/etc/acpi/events/power</tt> script from Ubuntu

Revision as of 20:58, 3 July 2010

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

First solution

If you want to shutdown your system by simply pressing the power button, do the following:

  1. Install the acpid package.
  2. If there is no hal in the DAEMONS array in rc.conf, add acpid to the DAEMONS array.
  3. Create a file in /etc/acpi/events/ named power with following content:
# /etc/acpi/events/power
# This is called when the user presses the power button

event=button/power (PWR.||PBTN)
action=/sbin/poweroff

To be able to test it, make sure the acpid daemon is started

If you do not have hal, start the acpid daemon yourself:

# /etc/rc.d/acpid start

Otherwise restart hal, it will take care of acpid:

# /etc/rc.d/hal restart

From now on, pressing the power button (lightly, not for a few seconds) should properly shutdown the system. Note that if you have hibernate configured and working you may want to change the last line with:

action=/usr/sbin/hibernate
Warning: Do not add the acpid daemon to the DAEMON array in "/etc/rc.conf" if hal is already there. You'll get an error message at boot when the computer tries to reload the already running acpi daemon.

If you're using a more sophisticated WM, you should use its own shutdown call, so it'd save its session etc.

KDE 3

Change the action (in /etc/acpi/events/power) to:

action=/opt/kde/bin/dcop --all-users --all-sessions ksmserver ksmserver logout 0 2 0

KDE 4

As of KDE 4.4, you can still use dcop as shown above.

Alternatively, you can use PowerDevil:

  1. Delete (or comment out) /etc/acpi/events/power.
  2. Open System Settings.
  3. Go to Advanced>>Power Management.
  4. Select "Edit Profiles" and choose the current profile. (In KDE 4.4, the default profile is "Powersave.")
  5. Select "Shutdown" as the action for "When power button is pressed."
  6. Press Apply.
Note: 1) With dcop and PowerDevil, the power button works only when KDE is running. Also, KDE needs to start from KDM (it probably also works when started from GDM). It does not work if you start KDE with a "startx" command.
Note: 2) The PowerDevil configuration is per user. To configure the power button for other users, repeat these steps for each user's account.

Todo: Add simple multi-user configuration steps.

XFCE

For XFCE4.4 change the action line to:

action=echo POWEROFF | /usr/lib/xfce4/xfsm-shutdown-helper

Note: For a more robust solution (If you are facing frequent WM crashes or working on a sacrificial PC for developing or testing your software...), you should take a look at "/usr/src/linux/Documentation/sysrq.txt", which is a kernel facility for yielding you (the user...) the CPU so that it could be used for any rescue work.

Second solution

(First solution not working for me)

1.Install acpid 2.Add acion for event - change file /etc/acpi/handler.sh:

...
case "$1" in
   button/power)
       #echo "PowerButton pressed!">/dev/tty5
       case "$2" in
           PWRF)   logger "PowerButton pressed: $2" 
		    /sbin/poweroff;;
           *)      logger "ACPI action undefined: $2" ;;
       esac
       ;;
...

3.Restart hal or acpid if you don't use hal:

# /etc/rc.d/hal restart

or

# /etc/rc.d/acpid restart

TODO

Add a technique that works regardless of VM (Gnome/KDE/xcfe/openbox/etc). Copy the /etc/acpi/events/power script from Ubuntu