通过电源按钮正常关机

roy*_*att 5 acpi systemd acpid

我希望能够通过按下电源按钮来关闭我的 CentOS 7 机器。由于它不能开箱即用,我尝试了以下操作:

yum -y install acpid
service acpid start
chkconfig acpid on
Run Code Online (Sandbox Code Playgroud)

不幸的是没有效果,可能是因为这仅对 CentOS 6.x 有效。有谁知道如何通过按电源按钮启用关机?

小智 2

我也有这个问题。

本质上,您将在日志中看到什么(如果 systemd 配置正确,以上任一方法都可以工作 - systemd 会为您转换旧的“服务”命令......至少在 CentOS7 中)

Nov 20 11:12:06 localhost systemd-logind: Power key pressed.
Nov 20 11:12:06 localhost systemd: SELinux policy denies access
Run Code Online (Sandbox Code Playgroud)

因此,您需要继续浏览 /var/log/audit/audit.log,您将看到如下内容:

init_t:s0 msg='avc:  denied  { start } for auid=-1 uid=0 gid=0 path="/usr/lib/systemd/system/poweroff.target" scontext=system_u:system_r:apmd_t:s0 tcontext=system_u:object_r:power_unit_file_t:s0 tclass=service  exe="/usr/lib/systemd/systemd" sauid=0 hostname=? addr=? terminal=?'
Run Code Online (Sandbox Code Playgroud)

好的,为什么系统配置文件不再位于 /etc 中?不管怎样,我离题了……关于 /usr/lib/systemd/system/poweroff.target 的东西关闭了?:顺便说一句,我真的很喜欢新的自动化文件现在如何混淆自己……现在没有真正的方向可走...这个文件完全没用。这些选项是什么意思?我猜测一些 PFY 管理员的工作保障......以及我的更多加班时间。(一定是另一个“功能”!)

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Power-Off
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-poweroff.service
After=systemd-poweroff.service
AllowIsolate=yes

[Install]
Alias=ctrl-alt-del.target
Run Code Online (Sandbox Code Playgroud)

好的,至此,我们已经有了足够的信息来真正寻找答案。问题在于 SELinux 策略阻止 systemd 关闭系统。

等等瞧!有一个错误: https ://bugzilla.redhat.com/show_bug.cgi?id=1224211

本质上,大约在评论 #60 左右,他们发现存在政策错误。它将通过定期更新来修复,但我只想安装“everything DVD”中的软件包。所以,看来我必须等到 CentOS 人员发布 7.2 才能解决这个问题!