Sunday, November 1, 2009

Headless Sun xVM VirtualBox guests via SMF

I finally had some extra time this weekend to sit down and finish an SMF manifest to support headless VirtualBox guests. Overall, I am quite pleased with the result:

The source for the service manifest and method script is available here. These files should be copied to /var/svc/manifest/application/virtualbox/ and /lib/svc/method/, respectively.

I have also created an IPS package for OpenSolaris users; if you are interested in installing the package, you will need to add my private IPS repository first:

% pfexec pkg set-authority -O http://arf.ubound.org/pkg/ arf.ubound.org
Once the repository has been added, you can then install the virtualbox-headless package:
% pfexec pkg install virtualbox-headless
Once the files are in place, you may need to import the manifest manually; since there are no default instances, svc:/system/manifest-import:default has a tendency to skip the manifest during a bulk import (this issue seems to affect the IPS package as well):
% pfexec svccfg import /var/svc/manifest/application/virtualbox/virtualbox-headless.xml
Once you have imported the manifest, it is time to add each guest you wish to manage. I have written the manifest such that a guest is identified by the name of the instance itself. For example, if I wanted to add a guest named qnx641, I would issue the following:
% pfexec svccfg -s virtualbox/headless add qnx641
You may then enable the instance via svcadm(1M):
% pfexec svcadm enable virtualbox/headless:qnx641
Two properties are provided to control the start and stop behavior of each instance:
  1. The vbox/start_type property corresponds to the --type argument passed to VBoxManage startvm; by default, it is set to headless. Possible values are: gui, sdl, vrdp, and headless, however only the last two really make any sense when used with SMF.

  2. The vbox/stop_method property corresponds to the argument passed to VBoxManage controlvm which is responsible for stopping the instance; by default it is set to savestate. Possible values are: pause, resume, reset, poweroff, savestate, acpipowerbutton, and acpisleepbutton
For those unfamiliar with SMF, these properties may be set by using this pattern:
% pfexec svccfg -s virtualbox/headless:qnx641
svc:/application/virtualbox/headless:qnx641> addpg vbox application
svc:/application/virtualbox/headless:qnx641> setprop vbox/stop_method = astring: "poweroff"
^D
Since this is a "wait" model service, it does not properly support a user shutting down the guest outside of svcadm(1M) invocations; the service will continue to report its status as online. In this case, a simple disable or restart will resolve the problem.

Enjoy!

6 comment(s):

  1. Sweet. I wrote an init.d script for that but this is better. Thanks for the good work.

    ReplyDelete
  2. proposal for an improvement:

    change

    74 <propval name='duration' type='astring' value='transient'/>

    to

    74 <propval name='duration' type='astring' value='child'/>

    and use

    start)
    /usr/bin/VBoxHeadless --startvm "$2" --vrdp \
    `/usr/bin/svcprop -c -p vbox/start_type $SMF_FMRI`

    as startmethod. major advantage: the process will be observed and automatically restarted which leads to a proper shutdown of the virtualmachine, when using acpipowerbutton. i've describe the problem of shutdown here. the possible options for starting the virtualmachine will change to on|off|config. i can send you the changed files if you are interested.

    ReplyDelete
  3. Is it possible to parameterize the user which runs the VirtualBox VM? I just modified the manifest for now... but it'd be nice to do this more cleanly.

    ReplyDelete
  4. All links to the files are dead.

    ReplyDelete
  5. Any chance of these files making a comeback? I'd love to compare your implementation to the one posted here http://adumont.serveblog.net/2009/07/21/virtualbox-smf/

    ReplyDelete
  6. You can find the files here...

    http://arf.ubound.org/repos/opensolaris/specfiles/file/7a0e006040a4

    Scroll down to the bottom and you'll see `virtualbox-headless.spec` and `virtualbox-headless.xml`

    Andy

    ReplyDelete

Note: Only a member of this blog may post a comment.