Shutdown Pressing Power Button (简体中文)

From ArchWiki
Revision as of 04:18, 18 October 2012 by Fengchao (Talk | contribs) (Remove space.)

Jump to: navigation, search

准备

首先,确保 button 模块 已被装载(检查lsmod的输出)。如果未被装载,需要手动装载。

systemd

logind负责处理电源按键事件,行为可以通过/etc/systemd/logind.conf配置。

sysvinit

按以下方法来做:

安装acpid软件包,将acpid加入到rc.conf的DAEMONS队列中(并且/或者执行/etc/rc.d/acpid start),然后在/etc/acpi/events/中创建一个文件,内容如下:

# /etc/acpi/events/power
# This is called when the user presses the power button

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

现在开始,按下电源开关(轻按,而不是长按几秒)就可以正常关闭系统了。 要注意,如果你已经正确配置好休眠(hibernate),你也许想将最后一行换为:

action=/usr/sbin/hibernate

无论如何,如果你使用更复杂的窗口管理器(WM),你应该使用它自己的关机调用,使得它可以进行保存会话等工作。

KDE中,可将action变为:

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

而对于XFCE4.4则变为:

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


注意:要更稳健的解决方案[If you are facing frequent WM crashes or working on a sacrificial PC for developing or testing your software...],你可以参阅"/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.