
我希望能夠透過按下電源按鈕關閉我的 CentOS 7 機器。由於它不能開箱即用,我嘗試了以下方法:
yum -y install acpid
service acpid start
chkconfig acpid on
不幸的是沒有效果,可能是因為這只對 CentOS 6.x 有效。有誰知道如何透過按電源按鈕啟用關機功能?
答案1
RHEL 7 以及 Centos 7 已從 System V (SysV) 啟動腳本和執行等級切換到 systemd。因此,啟動 acpid 的命令應該是:
systemctl start acpid
systemctl enable acpid
答案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
因此,您需要繼續瀏覽 /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=?'
好的,為什麼系統設定檔不再位於 /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
好的,至此,我們已經有了足夠的資訊來真正尋找答案。問題在於 SELinux 策略阻止 systemd 關閉系統。
等等瞧!有一個錯誤反對它: https://bugzilla.redhat.com/show_bug.cgi?id=1224211
本質上,大約在評論 #60 左右,他們發現存在政策錯誤。它將通過定期更新來修復,但我只想安裝“everything DVD”中的軟體包。所以,看來我必須等到 CentOS 人員發布 7.2 才能解決這個問題!