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.