起因
最近在用proxmox做虚拟机,都是开机后就丢在一边不管。但它的屏幕一直亮着,不会自动熄屏。网上查了些资料,都是用“setterm --blank 1”命令,是可以实现,重启后又要进去输一次太麻烦。想在登录帐号前执行,用以下方法解决:
新建rc-local.service文件
添加以下内容。把下面命令全部复制到提示符中运行。它的vi快捷键与centos7中的有点不同,改用cat很方便
cat > /etc/systemd/system/rc-local.service <<EOF [Unit] Description=/etc/rc.local ConditionPathExists=/etc/rc.local [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target EOF
新建rc.local文件
proxmox找不到rc.local文件,自己新建一个。
cat > /etc/rc.local <<EOF #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # bash /root/bindip.sh setterm --blank 2 exit 0 EOF
上图倒数第3行的命令中作用是两分钟后关屏幕
设置开机启动
把这两文件设置为开机启动,当然要先添加权限,最后检查它的状态
chmod +x /etc/rc.local systemctl enable rc-local systemctl start rc-local.service systemctl status rc-local.service
可以看到图片中Active:active (exited)……,说明成功了。