Difference between revisions of "Shutdown Pressing Power Button"
(amend previous edits, properly remove hal references (restore lost content)) |
(→First solution: accuracy disputed in talk page) |
||
Line 9: | Line 9: | ||
== First solution == | == First solution == | ||
− | + | {{Accuracy}} | |
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: | ||
Revision as of 11:35, 18 November 2011
Prerequisites
First of all, make sure that button
module is loaded (check the output of lsmod
). If it is not, load it manually with modprobe
and to load it automatically at boot time add it to your /etc/rc.conf MODULES
array.
First solution
If you want to shutdown your system by simply pressing the power button, do the following:
- Install the acpid package and add
acpid
to theDAEMONS
array in /etc/rc.conf. - Create a file in
/etc/acpi/events/
namedpower
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, see Daemon for instructions. To test it without actually shutting down, comment out the poweroff
line and check your user/messages logs.
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
If you are using a more sophisticated Window Manager, you should use its own shutdown call, so it would 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 Template:Codeline:
- Delete (or comment out) Template:Codeline.
- Open System Settings.
- Go to Advanced>>Power Management.
- Select "Edit Profiles" and choose the current profile. (In KDE 4.4, the default profile is "Powersave.")
- Select "Shutdown" as the action for "When power button is pressed."
- Press Apply.
- 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.
- The PowerDevil configuration is per user. To configure the power button for other users, repeat these steps for each user's account.
Xfce
For Xfce 4.4 change the action line to:
action=echo POWEROFF | /usr/lib/xfce4/xfsm-shutdown-helper
For Xfce 4.8 change the action line to:
action=echo POWEROFF | /usr/lib/xfce4/session/xfsm-shutdown-helper
Second solution
- Install the acpid package and add
acpid
to theDAEMONS
array in /etc/rc.conf. - Edit
/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 ;; ...
To be able to test it, make sure the acpid
daemon is started, see Daemon for instructions. To test it without actually shutting down, comment out the poweroff
line and check your user/messages logs.