Hello people,
I'm using "IdleAction=poweroff" in /etc/systemd/logind.conf but I want to prevent Workstation getting into Idle mode when a VM (I use KVM) is running.
I was thinking about "systemd-inhibit" but I am not sure it will do the trick.Do you have any ideas?
Prevent Idle when VM is running(KVM)
-
- Posts: 2019
- Joined: 2015/02/17 15:14:33
- Location: Bulgaria
- Contact:
-
- Posts: 2019
- Joined: 2015/02/17 15:14:33
- Location: Bulgaria
- Contact:
Re: Prevent Idle when VM is running(KVM)
Here is a brute-force method for anyone who needs this:
Set in root's crontab a task that runs every 5 min executing the following script:
This script will count the running VMs and if they are equal to 1 or more (you can use "$VM_COUNT" -gt "0" ) - then just run a sleep process for 5 min with a systemd-inhibitor. Once the script is over (and no more VMs are running) - the inhibitor is also removed.
Set in root's crontab a task that runs every 5 min executing the following script:
Code: Select all
VM_COUNT=$(ps -aux | grep ^[q]emu | wc -l)
if [ "$VM_COUNT" -ge "1" ]
then systemd-inhibit --mode=block sleep 300 &
fi