首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过电源按钮优雅关闭

通过电源按钮优雅关闭
EN

Unix & Linux用户
提问于 2014-10-04 21:30:00
回答 2查看 12.1K关注 0票数 5

我希望能够关闭我的CentOS 7机器,按下电源按钮。由于它无法发挥作用,所以我尝试了以下几种方法:

代码语言:javascript
复制
yum -y install acpid
service acpid start
chkconfig acpid on

不幸的是,没有效果,可能是因为这只适用于CentOS 6.x。有人知道如何通过按下电源按钮来启用关机吗?

EN

回答 2

Unix & Linux用户

回答已采纳

发布于 2015-11-20 18:04:04

我也有这个问题。

本质上,您将在日志中看到什么(如果systemd配置正确,上面的任何一种方法都有效--systemd为您翻译旧的“service”命令.(至少在CentOS7中)

代码语言:javascript
复制
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.log,然后您将看到如下所示:

代码语言:javascript
复制
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中了?不管怎样,我digress....something关于/usr/lib/systemd/system/poweroff.target是关闭的?:顺便说一句,我真的很喜欢新的自动文件现在是如何混淆自己的.现在没有真正的方向可走..。这个文件完全没用。这些选择中的任何一个意味着什么?我猜有些PFY管理员的工作安全.再给我加时赛。(一定是另一个“特征”!)

代码语言:javascript
复制
#  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策略。

看哪!有一个bug针对它:https://bugzilla.redhat.com/show_bug.cgi?id=1224211

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

票数 2
EN

Unix & Linux用户

发布于 2014-10-25 09:34:23

RHEL 7和Centos 7已经实现了从systemd (SysV)启动脚本和运行级到systemd的转换。因此,激活acpid的命令应该是:

代码语言:javascript
复制
systemctl start acpid
systemctl enable acpid
票数 4
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/159316

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档