VM start-up dependency

This is for discussing general topics about how to use VirtualBox.
Post Reply
Pok
Posts: 18
Joined: 1. Jul 2009, 14:00
Primary OS: Linux other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Linux, BSD, Windows

VM start-up dependency

Post by Pok »

Is it possible to start a VM any time another VM is started?
Say one has VMs A, B and C.
I would like to start A if either B or C are started, if A is not yet running.
The catch is that this should work no matter how B or C have been started (API, UI or command line).

I am currently running VirtualBox 7.0.26 on Slackware64 (Linux).
Galactic
Posts: 83
Joined: 28. Apr 2016, 04:52

Re: VM start-up dependency

Post by Galactic »

The main way I know how to do this is to use a shell script to periodically poll VirtualBox to see if the VMs are running. You can either use a loop with a sleep command or a cron job to perform the check every so many seconds.

These commands will check the running status of a VM:

Code: Select all

vboxmanage showvminfo '{UUID} or VM Name' --machinereadable | grep -c -i 'VMState="running"'

vboxmanage list runningvms | grep -c -i '{UUID} or VM Name'
The second option has a faster execution time.

Just check if the result is greater than zero (i.e. grep found at least one match) for VMs B or C. If so, use the same method to check if VM A is running already. If not, then start it with:

Code: Select all

vboxmanage startvm '{UUID} or VM Name'
Post Reply