Hi SimonF,
I want to thank you again for great work and support.
I was unable to reply before, and even if I am giving up on unraid as my main working setup,
I want to give feedback to what has worked for me.
I used this in before sleep hook:
#!/bin/bash
date >> /boot/logs/sleep.log
echo "Sleeping ..." >> /boot/logs/sleep.log
# Get a list of all VMs that are running
domains=$(virsh list --all | grep running)
# Check if the previous command returned any data - If no VMs are running, the variable 'domains' will be empty
if [ -z "$domains" ]
then
# Nothing to do here - exit
echo "No VMs are running" >> /boot/logs/sleep.log
exit 0
fi
# 1 or more VMs are running
echo "Found the following VMs running:" >> /boot/logs/sleep.log
echo "$domains" >> /boot/logs/sleep.log
# Get a list of the VM IDs
domains=($(virsh list --all | grep running | awk '{ print $1 }'))
# Issue the suspend command to each VM that is running
for domain in "${domains[@]}"; do
echo "Issuing the dompmsuspend and USB disconnect command to VM $domain" >> /boot/logs/sleep.log
virsh dompmsuspend $domain mem
sleep 5
rc.usb_manager vm_action $domain disconnect
sleep 5
done
and the following in after wake-up:
#!/bin/bash
date >> /boot/logs/sleep.log
echo "Waking up ..." >> /boot/logs/sleep.log
# Get a list of all VMs that are pmsuspended
domains=$(virsh list --all | grep pmsuspended)
# Check if the previous command returned any data - If no VMs are pmsuspended, the variable 'domains' will be empty
if [ -z "$domains" ]
then
# Nothing to do here - exit
echo "No VMs are pmsuspended" >> /boot/logs/sleep.log
exit 0
fi
# 1 or more VMs are pmsuspended
echo "Found the following VMs pmsuspended:" >> /boot/logs/sleep.log
echo "$domains" >> /boot/logs/sleep.log
# Get a list of the VM IDs
domains=($(virsh list --all | grep pmsuspended | awk '{ print $1 }'))
# Issue the resume command to each VM that is pmsuspended
for domain in "${domains[@]}"; do
echo "Issuing the USB prepare and dompmwakeup command to VM $domain" >> /boot/logs/sleep.log
rc.usb_manager vm_action $domain prepare
sleep 5
virsh dompmwakeup $domain
done
which resulted in following log file:
Mon Mar 18 17:21:23 CET 2024
Sleeping ...
Found the following VMs running:
4 TheMainWindows10 running
Issuing the dompmsuspend and USB disconnect command to VM 4
Mon Mar 18 17:22:06 CET 2024
Waking up ...
Found the following VMs pmsuspended:
4 TheMainWindows10 pmsuspended
Issuing the USB prepare and dompmwakeup command to VM 4
The scripts can obviously be less verbose, but I needed it for troubleshooting and adjusting sleep fudge factor.
As said I am moving from my idea of one in all system, as cons outweigh the pros, and I will be running one pure Windows machine I need for my work, and another, most likely, unraid (zfs) for backups.
Thanks again, and keep up the good work