Managing A VirtualBox Guest Using Upstart

Thursday, August 11, 2011

With a Windows 7 guest comfortably installed on my Ubuntu host, I turn my attention to making it automatically boot and shutdown with the host. Traditionally, we would use a SysV-style init script that uses VBoxManage/VBoxHeadless to start the guest and VBoxManage to stop it. Upstart seems to be the way to go now, so let’s make a configuration file for that. And instead of powering off the guest every time (which should be done using ACPI events), it would be easier and faster to simply save the running state and restore it during the next boot.

As before, the VM is named mustard, my username is inportb, and this file is called /etc/init/mustard.conf

description “mustard VM”
author “Jiang”

start on (local-filesystems and net-device-up IFACE=eth0)
stop on runlevel [016]

console output

respawn
respawn limit 5 10

pre-stop script
su inportb -c “VBoxManage controlvm mustard savestate”
end script

exec su inportb -c “VBoxHeadless –startvm mustard”

As soon as the local filesystems are ready and the network is up, Upstart would run VBoxHeadless and monitor the process. Should the process die unexpectedly (such as if someone hits the guest’s shutdown button by mistake), Upstart would bring it right back up. Furthermore, if some problem keeps terminating the process soon after starting, Upstart would stop trying after 5 bounces in 10 seconds. The “correct” way to start and stop the guest, respectively, would be through the host…

sudo start mustard
sudo stop mustard

One Comment

    Leave a Reply

    Pingbacks & Trackbacks

    1. inportb » Setting Up A VirtualBox Guest On A Headless Linux Host - Pingback on 2011/08/11