shutdown-all-vms - 1.1.2

added slight delay between shutdown commands.
main
superrob1500 2025-09-01 16:53:05 +02:00
parent 0f9ac29b75
commit 561009e718
1 changed files with 7 additions and 4 deletions

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
# Script to try to gracefully shut down all running VMs on a Proxmox host, before then force stopping them. # Script to try to gracefully shut down all running VMs on a Proxmox host, before then force stopping them.
# Running as a sub-script of apcupsd's doshutdown function to ensure that VMs are shut down before the host is powered off. # Running as a sub-script of apcupsd's doshutdown function to ensure that VMs are shut down before the host is powered off.
#v1.1.1 #v1.1.2
# Get a list of running VMs # Get a list of running VMs
vmlist=$(qm list | grep running | awk '{print $1}') vmlist=$(qm list | grep running | awk '{print $1}')
@ -12,22 +12,24 @@ echo "VM(s) $vmlist"
echo "Container(s) $lxclist" echo "Container(s) $lxclist"
# Loop through the list and force shutdown each VM # Loop through the list and force shutdown each VM
echo "Stopping VM(s)..." echo "Shutting down VM(s)..."
for vmid in $vmlist for vmid in $vmlist
do do
echo "Sending shutown command to VM $vmid" echo "Sending shutown command to VM $vmid"
qm shutdown $vmid & qm shutdown $vmid &
sleep 2
done done
echo "Stopping container(s)..." echo "Shutting down container(s)..."
for lxcid in $lxclist for lxcid in $lxclist
do do
echo "Sending shutown command to container $lxcid" echo "Sending shutown command to container $lxcid"
pct shutdown $lxcid & pct shutdown $lxcid &
sleep 2
done done
# Wait for 2.5 minutes to allow VMs to shut down # Wait for 2.5 minutes to allow VMs to shut down
echo -e "\nWating for shutdowns to complete." echo -e "\nWating 2.5 minutes for shutdowns to complete."
sleep 150 sleep 150
# Get a list of running VMs again # Get a list of running VMs again
@ -55,4 +57,5 @@ if [[ -n "$vmlist" || -n "$lxclist" ]]; then
fi fi
# Exit with success # Exit with success
echo -e "\nShutdowns complete."
exit 0 exit 0