拦截电源关机按键、自定义功能

拦截电源关机按键、自定义功能
#忽略gnome自带的电源管理
sed -i "s/#HandlePowerKey=poweroff/HandlePowerKey=ignore/g" /etc/systemd/logind.conf
systemctl status systemd-logind
yum install acpid
systemctl disable acpid
#如果以systemctl start acpid方式启动acpid, /etc/acpi/actions/power.sh里的命令只有shutdown -h now能执行成功, 其它命令kill echo touch 均执行不成功, 只能以#acpid启动
/etc/profile尾部添加
########################
alreadyStart=$(ps -elf | grep acpid | grep -v grep | wc -l)
if [  0 == ${alreadyStart} ] ; then
acpid
fi
########################
/etc/acpi/actions/power.sh 删除所有行, 添加自定义关机按键功能, 什么都不写就是屏蔽掉了关机按键功能
在此文件中添加如下几句,实现给screenserver进程发信号,让进程处理此信号(进程内部实现关闭屏幕、关闭操作系统)
########################
#!/bin/sh
PATH=/sbin:/bin:/usr/bin
kill -12 $(ps -elf | grep screenserver | grep -v grep | awk '{print $4}')
########################
原文地址:https://www.cnblogs.com/LiuYanYGZ/p/9568912.html