From 6376f9300be99442cfaa7908ea7ceddfa7ccebe4 Mon Sep 17 00:00:00 2001 From: Dmitry Badovsky Date: Sat, 1 Nov 2025 13:00:03 +0000 Subject: [PATCH] Update vmcreate.sh --- vmcreate.sh | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/vmcreate.sh b/vmcreate.sh index 70bc567..a0221b5 100644 --- a/vmcreate.sh +++ b/vmcreate.sh @@ -117,10 +117,26 @@ REMOVE () { do ip=$(echo -n "$line" | cut -d ';') vmid=$(get_vmid "$ip") - snippet="${path}${vmid}_${template}" qm stop $vmid - if [ $harule ]; then ha-manager remove vm:${vmid}; fi - qm destroy $vmid --destroy-unreferenced-disks --purge + echo "VM $vmid is stopping." + done + for line in (cat hosts.tmp) + do + ip=$(echo -n "$line" | cut -d ';') + vmid=$(get_vmid "$ip") + snippet="${path}${vmid}_${template}" + status=$(qm status $vmid | cut -d ' ' -f 2) + until [[ $status -eq "stopped" ]] + do + echo "Waiting for VM $vmid become stopped..." + sleep 1 + done + ha-manager remove vm:${vmid} &>/dev/null && + echo "VM $vmid removed from HA" + qm destroy $vmid --destroy-unreferenced-disks --purge && + echo "VM $vmid successfully removed" + rm "$snippet" && + echo "Snippet $snippet removed" done }