I would go with a combination of cron job and usage of vboxmanage via bash scripts.
I'd have a bash script which would start up the virtual machines and fire up a cron job for checking the status of the machines.
The script should look something like:
#!/bin/bash
vboxmanage startvm "Server App VM name"
vboxmanage startvm "Windows XP VM name"
crontab ~/check_vms_and_shutdown_job.txt
Let's say we save it as start_vms_and_cronjob.sh
. Remember to chmod +x
it, so it can be actually executed.
You might wonder about the check_vms_and_shutdown_job.txt
file. It's a text file containing information about a job that should be run at certain intervals. In this example we placed it in the user's home folder and it should read:
*/5 * * * * ~/check_vms_and_shutdown.sh
This file should have a new line at the end of the line (press enter before saving ;) ) What this file does is that it describes a cron job which is run every 5 minutes and it executes a bash script.
Now what is this check_vms_and_shutdown.sh
script you might ask? Well, here's the whole point. It should say:
#!/bin/bash
if vboxmanage list runningvms | grep "Windows XP VM name"
then
echo "Windows XP still running."
else
echo "Windows XP shut down. Shutting down the rest."
vboxmanage controlvm "Server App VM name" savestate
crontab -r
shutdown -h now
fi
Now what it does, that it will check if there is the XP virtual machine running. If it's not, it will then order the server app virtual machine to save it's state. After that the cronjob will be removed and the system shut down. Remember to chmod +x
and here we also placed the file in user's home folder.
For convenience and better usage on the purpose you might also want to run the virtualboxes headless and have their usage be done through remote display.
Now add the start_vms_and_cronjob.sh
into your startup applications and you should be set.
So what we have here is:
- When the system starts, the virtual machines are started by a shell script and a new cron job (running a shell script) is created from a cron job rule txt file.
- In every 5 minutes the cron job runs the script which checks if the XP virtual machine is still running and if not it will save the other virtual machine, remove the cron job and shutdown the system.
Hope this helps you to configure just what you need.