diff --git a/scripts/vm/thornsec.vm.control.stopVM b/scripts/vm/thornsec.vm.control.stopVM index 301dc2f4..7a96fd33 100644 --- a/scripts/vm/thornsec.vm.control.stopVM +++ b/scripts/vm/thornsec.vm.control.stopVM @@ -17,16 +17,27 @@ stopVm() { (( pullPlug-- )); sleep 1; done; + if sudo -u vboxuser_"${vm}" VBoxManage showvminfo "${vm}" --machinereadable | grep running + then + exit 0 else - printf "...no need!\n\n"; - sudo -u vboxuser_"${vm}" VBoxManage controlvm "${vm}" acpipowerbutton; - fi; - - if vmRunning "${vm}" && [ ${pullPlug} -eq 0 ]; then - printf "15 seconds has elapsed.\nPulling the plug.\n\n"; - sudo -u vboxuser_"${vm}" VBoxManage controlvm "${vm}" poweroff; - wait $!; + echo "Attempting holding down the (virtual) powerbutton" + sudo -u vboxuser_"${vm}" VBoxManage controlvm "${vm}" poweroff + sleep 30 fi + ## + ## We actually want to do a pgrep on the VMS and kill -9 it before we discard the state, but this is like totally and emergency thing if the VM will netiher start nor turn off + ## if sudo -u vboxuser_"${vm}" VBoxManage showvminfo "${vm}" --machinereadable | grep poweroff + ##then + ## exit 0 + ##else + ## echo "Bugger, okay pulling the (virtual) power cord" + ## sudo -u vboxuser_"${vm}" VBoxManage discardstate "${vm}" + ##fi + ##else + ## printf "...no need!\n\n"; + ## sudo -u vboxuser_"${vm}" VBoxManage controlvm "${vm}" acpipowerbutton; + ##fi; return $?; }