PVE Host
Table of Contents
开启自动睡眠
vim /etc/systemd/logind.conf
如下设置将开启空闲超过30分钟后自动睡眠。
IdleAction=suspendIdleActionSec=30min
Trigger new settings
systemctl restart systemd-logind
当guest运行时,禁用休眠功能
后台启动如下进程即可:
- 检测代码
#!/usr/bin/env bashvmid=100while true; doactive_count=$(/usr/sbin/qm satus 100 | grep running | wc -l)if [[ $active_count -gt 0 ]]; then# inhibit host sleepsystemd-inhibit --what=sleep \--who="Proxmox Guest" \--why="Guest VM is running" \sleep 30fi# wait for 1 second before checking againesleep 1done
systemd service
[Unit]Description=PVE guest status monitorAfter=network.target[Service]ExecStart=/usr/local/bin/pve-guest-monitor.shExecReload=/bin/kill -HUP $MAINPIDKillMode=processRestart=on-failureRestartSec=42s[Install]WantedBy=multi-user.target
一键安装脚本
the whole script can be found at: assets/.pve-prevent-host-sleep.sh