Virtualbox has the ability to issue a command to a running vm:
vboxmanage controlvm NameOfRunningVM acpipowerbutton
However this command returns immediately which results in non-graceful shutdown for my situation.
The situation: I plan on using this in an /etc/init.d script. This would allow for graceful shutdown of all the running VMs. Currently when I issue the vboxmanage controlvm NameOfRunningVM acpipowerbutton
command the shutdown gets cutoff because the command doesn't wait for the VM to shutdown.
I need a Bash script that takes as input the name of the Virtualbox machine and a timeout in seconds then waits for the VM to return to "poweroff" state or the timeout occurs?
I'm not sure what is the best way to go about doing this.
I was thinking of checking the state of the VM with the following command:
[user@machine ~]$ vboxmanage list runningvms
"VirtualMachineName" {65c93f1f-4508-4119-b07d-ce9e89b23b8e}
The bash script would maybe be polling for a list of running VMs. Once the machine name stops being listed, the VM would be considered finished.
ping
the VM(s), and wait for that to fail before allowing the host to shut down? (You might want to allow a few seconds afterping
failure for the VM to completely shut down.) Or is there some command specific to Virtualbox that would let you query the status of a VM?