HOWTO - virtualbox as a service on Windows (srvstart.exe)

Discussions related to using VirtualBox on Windows hosts.
rasker
Posts: 32
Joined: 6. Mar 2009, 15:27

HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by rasker »

This howto describes a method of running virtualbox as a service on Windows using the srvstart.exe service wrapper

srvstart.exe is a tool written by Nick Rozanski for running any application or script using the Windows service manager. It wraps a normal application/script providing it with an interface to Windows service manager. This allows Windows to start Virtualbox at boot and stop it at shutdown or at your request. Srvstart.exe is a better solution than Microsoft's srvany.exe and NT Wrapper because it allows you to configure how a service should be stopped properly. When you first start using srvstart you might get some vebose feedback from the program which can be confusing but you should push through this as srvstart is a good program to use for our purpose (safely start/stop Virtualbox machines). This howto will run through the steps needed to configure a single virtual machine. To configure more you just need to repeat the howto with different service names and different virtual machine names.

Pre-requisites
  1. A version of VirtualBox that supports the vboxheadless interface and vrdp (vrdp is a requirement of vboxheadless).
  2. A copy of the srvstart.exe binary which can be gotten from here. The main website for srvstart is Nick Rozanski's website.
  3. Download and Install Windows Service Commander from here
  4. For troubleshooting you might also want to get a copy of Process Explorer from Sysinternals from the technet site - > here
The Steps
  1. The first step is to build your virtual machine as you would any virtualbox machine and make sure it works as you wish.
  2. Next, close the VirtualBox GUI and copy the virtualbox.xml file from the c:\Documents and Settings\<your_login_name>\.VirtualBox\ directory to the c:\Documents and Settings\LocalService\.VirtualBox\ directory. Create the .VirtualBox directory if it doesn't already exist. This allows VirtualBox to get the right config when it is executed from the LocalService account. (Each time you want to change the hardware configuration of a virtual machine running as a servie, stop the machine running, make the coinfiguration change using the virtualbox frontend, test the virtual machine, and once all is how you want it to be, repeat this step).
  3. Create a directory in c:\Program Files\ called srvstart. Copy (extract) all the files from within the zip archive you downloaded earlier to the srvstart directory (particularly, logger.dll, srvstart.dll, srvstart.exe, svc.exe).
  4. Next We need to create a configuration file that configures srvstart and describes our service to srvstart. Using your notepad or your favourite text editor create a file called <virtual machine name>.srvstart.ini in c:\program files\srvstart\. e.g. c:\program files\srvstart\VBOX_LINUX.srvstart.ini.
    1. paste this into the file (assuming your vmachine is called VBOX_LINUX, see below for a complete explanation) :

      Code: Select all

      env=VBOXGUI="C:\Program Files\Sun\xVM VirtualBox\virtualbox.exe"
      env=VBOXHEADLESS="C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe"
      env=VBOXWEBSRV="C:\Program Files\Sun\xVM VirtualBox\vboxwebsrv.exe"
      env=VBOXMANAGE="C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe"
      env=VBOX_PROG="C:\Program Files\Sun\xVM VirtualBox\"
      env=VBOX_BASE="d:\vbox\"
      env=VBOX_MACHINES="d:\vbox\machines"
      env=VBOX_VDI="d:\vbox\VDI"
      env=VBOX_MACHINE1=vbox_linsrv
      
      [VBOX_LINUX]
      startup=%VBOXHEADLESS% -startvm VBOX_LINUX
      shutdown_method=command
      shutdown=%VBOXMANAGE% controlvm VBOX_LINUX savestate
      debug=0
      debug_out=>d:\vbox\VDI\VBOX_LINUX.log
      
      Save this file.
    2. Start Windows Service Commander and select Tools -> Install New Service from the menu. this will start a wizard to help you set the service up. Click Next
      • In the Enter Path to the service executable: box, click Browse and browse to and select the c:\Program Files\srvstart\srvstart.exe file.
      • Append the following to the command line : svc VBOX_LINUX -c "c:\Program Files\srvstart\srvstart.ini"
      • check that it looks something like :

        Code: Select all

        c:\Program Files\srvstart\srvstart.exe svc VBOX_LINUX -c "c:\Program Files\srvstart\srvstart.ini"
      • Leave the Service will run in it's own process radio button selected and click Next.
      • Give your service a name e.g. VBOX_LINUX, a Display Name (which can be the same as the Service Name) and a brief description of the virtual machine. Click Next.
      • Leave the LocalSystem account radio button selected and click the Allow service to interact with desktop checkbox. Click Next.
      • Set the startup options as you wish (defaults are good for now). Click Next twice (skip the Dependencies page) and click Finish.
    If you look down the list in Windows Service Commander you will see your newly created service!

    Notes

    As usual there are a few caveats and issues. However the srvstart method is better than using srvany or NT wrapper and the like and perhaps nearly as good as vboxvmservice .
    1. A useful feature is that once you have setup a Windows service to run srvstart you can change the configuration just by editing the ini file and restarting the service. No need to edit the Windows Service anymore.
    2. The parameter after the svc parameter in the service command line should be exactly the same as the keyword in the ini file which is enclosed in square brackets. Within the ini file, you can change the virtualbox machine name to your own virtual machine (the parameters after the startvm and controlvm switches).
    3. Don't assign a startup_dir keyword if the startup directory has white space in it. It seems to never work even with the environment variable work around. This is not a big issue as it is not usually needed anyway.
    4. Use Windows Service Commander to create/delete/edit windows services. The included SVC tool and the srvstart install command's are a bit flaky (parsing parameters).
    5. The key reason to use srvstart is because we can stop the virtual machine in the correct way (the above configuration saves the state) by using the vboxmanage controlvm command. You could also try an acpi shutdown. Saving state and closing is probably good enough though.
    6. srvstart does not do any smart checking of the parameters passed to it. In particular it fails to Do The Right Thing (tm) when passed parameters with white space in them. This is why some parameters are passed, quoted, in environment variables, more because this works (as in worksaround) than because it is the right way.
    7. If possible define the vrdp port number in the machine settings not the vboxheadless command line if you are using the savestate method of shutting down. You can get a conflict which prevents the virtual machine from starting up.
    8. Stopping the service usually successfully terminates the vboxheadless processes. Unfortunately the VBoxSvc process does not always do the right thing and go away. This is particularly true if you start the virtualbox Gui while the service is started. This can leave locked files behind which prevent you from either starting the virtualbox gui or accessing the machine from the gui if the gui can be started and other issues.
    9. This method opens a console window (note not a command window). Virtualbox fails with some weird error if it can't send output to stdout (I'm guessing) so it is essential that the console window is allowed. Closing this window will kill the vboxheadless process. There are various utilities that you can use to try and start the service without the console window (by running the vboxheadless from a batchfile for example and running the batchfile as a service but this is messy and unreliable).
    10. Use Process Explorer to see what is really going on.
    11. Some error codes you might see from srvstart in the Application Event log:
      • Srvstart will usually throw error messages from the win32 api which are usually related to some problem with createprocess(). here is a cheatsheet
      • Error 267 and Error 2: Win32 directory/filenot found errors. If you have double checked the parameter then this is usually a problem with srvstart not parsing input parameters properly (stopping at the first white space). Assign the parameter (with quoting) to an environment variable with the env keyword and use the env. variable (using the usual %var% format) in place of the parameter.
      • -xxxxxxxxx: (a large minus number like exit code -2135228415) virtualbox probably could not create/find a stdout/stderr. Tick the Interact with desktop checkbox in the windows service configuration.
Last edited by rasker on 24. Mar 2009, 12:30, edited 4 times in total.
rasker
Posts: 32
Joined: 6. Mar 2009, 15:27

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by rasker »

SRVSTART.INI EXAMPLE

This is an example srvstart.ini file.

Code: Select all

#An example ini file for SRVSTART

#The Windows service can be called anything you want.

#The srvstart commandline should refer to the [] section in this file exaclty (case sensitive)  


env=VBOX_USER_HOME=
env=VBOXGUI="C:\Program Files\Sun\xVM VirtualBox\virtualbox.exe"
env=VBOXHEADLESS="C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe"
env=VBOXWEBSRV="C:\Program Files\Sun\xVM VirtualBox\vboxwebsrv.exe"
env=VBOXMANAGE="C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe"
env=VBOX_PROG="C:\Program Files\Sun\xVM VirtualBox\"
env=VBOX_BASE="d:\vbox\"
env=VBOX_MACHINES="d:\vbox\machines"
env=VBOX_VDI="d:\vbox\VDI"
env=VBOX_MACHINE1=vbox_linsrv

#The srvstart commandline should refer to the name in [] exactly (case sensitive)  
[VBOX_LINUX]

#the command to start the virtual machine
startup=%VBOXHEADLESS% -startvm VBOX_LINUX

the command to stop the virtual machine
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm VBOX_LINUX savestate

#set to 1 for more debug messages from srvstart (note: not from virtualbox) 
debug=0
#point the debug file somewhere (note the > to overwrite an older log file)
debug_out=>d:\vbox\VDI\VBOX_LINUX.log
Last edited by rasker on 15. Mar 2009, 04:22, edited 1 time in total.
rasker
Posts: 32
Joined: 6. Mar 2009, 15:27

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by rasker »

ANNOTATED GENERIC SRVSTART INI

And here is a generic srvstart.ini file with most of the options/keywords explained
(basically a summary of the srvstart documentation when used in service mode and with a config file)

Code: Select all

# An annotated generic srvstart control file (with all options listed)
#   SRVSTART reads the control file, applying all keywords before the first section
#   (Sections are defined by square brackets [], similar to windows ini file conventions)
#   It then finds the section whose name matches the supplied window or service name,
#   and applies all keywords in that section.
#
#  To use an option uncomment the line beginning ##


# *****   GLOBAL OPTIONS   *****
#   Global options apply to all services managed by that ini file.


# ***  Environment Variable Options  ***
#
#    Note that SRVSTART applies environment variable substitution to all keyword
#    values which are filenames, pathnames or directories (new in version 1.1).
#    For this to work, the environment variable must already be defined
#    (either globally to Windows NT or using the env directive) at the time that
#    the directive is read.

# ENV=var=value
#   Set the environment variable var equal to value before running the program
#     Environment values which contain embedded environment variables will have
#     these substituted, but only if they are already defined. For example:
#       myvar1=myvalue1
#       myvar2=my_%myvar1%_val
#     will set myvar1 to myvalue1 and myvar2 to my_myvalue1_val. However
#       myvar2=my_%myvar1%_val
#       myvar1=myvalue1 ...
#     will set myvar2 to my_%myvar1%_val (since myvar1 is not defined at this point.
#
#   Note that in service mode, the only environment variables available when SRVSTART
#   starts are the system environment variables. (These are the environment variables
#   in the upper list box in In #   Control Panel|System|Environment.) If the service
#   is started using a named Windows NT account, then the environment for that account
#   will also available.
#
##env=var=value

# PATH=path
#   set the value of the %PATH% environment variable to path
#    Default path if not given : %SYBASE%\install;SYBASE%\bin;%SYBASE%\dll;%SystemRoot%;%SystemRoot%\system32
#
##path=path


# ***  Sybase Environment Variables  ***

# SYBASE=sybase
#   Set the value of the %SYBASE% environment variable to sybase
#
##sybase=sybase

# SYBPATH=path
#   Assign a default %PATH% based on this value of sybase instead of value supplied using sybase=
#
#   The sybpath option assigns a path as in the path option, but using the value supplied to sybpath, instead of sybase=.
#   For example, -q C:\NEWSYB would assign a path of the form C:\NEWSYB\install;C:\NEWSYB\bin;... etc.
#
##sybpath=path

# LIB=libdir
#   set the value of the %LIB% environment variable to libdir#
#
##lib=libdir


# ***  Process Options   ***

#  PRIORITY-priority
#   start the command at the given execution priority(idle, normal, high, real) 
#
#    * idle to run only when the CPU is otherwise idle
#    * normal to run at normal priority
#    * high to run at high priority
#    * real to run at real time priority 
#
##priority=priority


# ***  Startup Options  ***

# STARTUP_DELAY=seconds
#    How long SRVSTART waits before reporting a "started" status to the NT Service Control Manager
#
# SRVSTART waits this number of seconds before reporting to the Windows NT Service Control Manager that the service has started.
# Use this option if the command takes a long time to initialise (default zero).
#
##startup_delay=seconds

# WAIT_TIME=seconds
#   program status check interval in seconds
#
#   SRVSTART regularly checks the process it has started to see if it is still running.
#   If it has finished, then SRVSTART reports a "service stopped" status to the Service
#   Control Manager and then exits. WAIT_TIME defines how often this check is done (default every second). 
#
##wait_time=seconds


# ***  Drive Mappings  ***

# NETWORK_DRIVE=driveletter=networkpath
#   This directive maps the drive driveletter (do not include the colon) to the network path networkpath
#
#   networkpath should be a full network path including the host name and initial backslashes.
#   Note that for this to work, the service must be started using a named user who has the
#   appropriate privileges to access networkpath (since LocalSystem) does not have any network privileges.
#
##network_drive=driveletter=networkpath

# LOCAL_DRIVE=driveletter=localpath
#   This directive maps the drive driveletter (do not include the colon) to the local path networkpath
#
#   This is analogous to entering the SUBST command at the command line.
#   networkpath should be a full pathname including the drive letter. Note that such
#   substitutions are global and immediately visible to other users on the same computer.
#   No special privileges are required (ie LocalSystem has sufficient authority to do this). 
#
##local_drive=driveletter=localpath




#  *****   DEBUGGING OPTIONS   *****
#   Debugging options apply to the srvstart process itself not the managed services.

# DEBUG=level
#    set the SRVSTART debug level: 0=none, 1=normal, 2=verbose
#       *  0 prevents any output other than error messages.
#       *  1 outputs a few informational messages.
#       *  2 outputs a large number of debug messages. 
#
#    Note that you must use the Debug executables for level 2 (you can find these in the Debug directory of the full distribution).
#
##debug=level

# DEBUG_OUT=target 
#   By default, SRVSTART logs error messages to the Event Log in service mode, and to stdout otherwise.
#
#    * -          hyphen : messages will go to stdout. This does not apply to service mode (messages will just disappear).
#    * LOG        LOG (uppercase) : debug messages will be sent to the Windows NT Event Log.
#    * pathname   Debug messages will be appended to this file. 
#
#   For example, the directive debug_out=%TEMP%\myservice.out will log debug output to the
#   file myservice.out in a temporary directory.
#
#   If target is a path name whose first character is > (greater than), SRVSTART will truncate the file before writing to it.
#
##debug_out=target




# *****  SERVICE DEFINITION  *****
#   A single instance of SRVSTART can manage multiple individual services of it's own.
#   This is comparable to the way the windows svchost does things.
#   (duplicate the following for each service you want to run)

# [MY_SERVICE]
#   SRVSTART managed services are defined in ini style congiuration sections
#   (each begun with square brackets [], with the square bracket containing the name
#   of the managed service). The service definition ends either at the start of
#   another service definition or the end of file.
#
##[MY_SERVICE]

# STARTUP=program
#   This defines the service program command. It replaces the program and program_parameters which are supplied on the SRVSTART command line.
#   You must provide a startup directive for each service which starts using a control file. All other directives are optional.
#   e.g. startup=C:\MYPROG\MYPROG.EXE -a -b -c xxxx yyyy zzz
#
#   The command to run, program [ program_parameters ] may be any executable program, that is anything with extension .com, .exe or .bat.
#   program and program_parameters may refer to environment variables using the %var% syntax.
#     (These will be substituted (not recursively, which is done while defining the environment variables) where encountered
#     For example %HOME%\bin\mycommand.exe %SYSTEMROOT%.)
#
##startup=program [ program_parameters ...]

# STARTUP_DIR=path
#   This defines the startup directory. It should be a full pathname including a drive letter.
#
##startup_dir=path

# WAIT=program
#   This defines a command that SRVSTART will run after starting the service program. 
#
#   This should wait for the service program to enter a "running" state (eg wait for a database server to complete recovery).
#   It should exit with a status of 0 once the service program is up and running.
#   It should exit with a non-zero status if the service program has failed or is never going to enter a running status.
#   Once this command has exited with a status of 0, SRVSTART considers that the service program is running.
#
##wait=program [ program_parameters ... ]

# SHUTDOWN_METHOD={kill | command | winmessage}
#    This defines the action that SRVSTART will take to shutdown the service program (service mode only).
#    SRVSTART will take this action if it receives a "shutdown" request from the SCM
#    (eg a user runs NET STOP or stops the service using Control Panel | Services).
#     * For shutdown_method=kill, SRVSTART will shut down the service program using the Win32 TerminateProcess() API.
#     * For shutdown_method=command, SRVSTART will run the command given by the shutdown directive.
#     * For shutdown_method=winmessage, SRVSTART will send a Windows CLOSE message to all Windows
#       opened by the service program (new in version 1.1). 
#
#   kill is the default, and this directive can be omitted.
#   Note that kill is equivalent to a Unix kill -9 and leaves DLLs in an undefined state (ie it does not call the DLL termination routines).
#   I have not to date observed any problems with this (but it clearly depends on the program you are shutting down).
#   Note also that winmessage will not work for Win32 console programs.
#
##shutdown_method={kill | command | winmessage}

# SHUTDOWN=program
#   This defines a command to shut down the service program.
#
#   SRVSTART will run this command if it receives a "shutdown" or stop request from the SCM
#   (eg a user runs NET STOP) or stops the service using Control Panel | Services.
#   If this directive is provided, then shutdown_method=command is implied and can be omitted.
#
##shutdown=program [ program_parameters ... ]

# AUTO_RESTART={y|n}
#   This enables service restart if the SRVSTART service exits UNEXPECTEDLY
#
#   If auto_restart is set, then SRVSTART will restart the service program if it
#   exits for any reason. (The assumption here is that the service has crashed.)
#   auto_restart does not, of course, restart the service program if it is stopped by request (eg NET STOP or Control Panel|Services).
#   auto_restart does not restart the service program if it thinks that Windows NT is shutting down.
#     Unfortunately it does not appear to be possible to determine this unambiguously.
#     If you are irritated by services restarting during Windows NT shutdown, then increase the value of restart_interval to, say, a minute. 
#
##auto_restart={y|n}

# RESTART_INTERVAL=seconds
#   auto_restart is enabled and restart_interval is defined, then before restarting, SRVSTART will wait seconds seconds.
#
##restart_interval=seconds
You can copy and paste it into your own ini file and work through each section chosing to enable/disable each feature.
Last edited by rasker on 15. Mar 2009, 04:23, edited 2 times in total.
rasker
Posts: 32
Joined: 6. Mar 2009, 15:27

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by rasker »

Multiple Virtual Machines

To start multiple virtual machines as services you have two options.

Either:

Create an ini file for each virtual machine and setup Windows services to point to the different ini files

Or:

Create one ini file with additional sections (differentiated by [] names) and use the srvstart command parameters to select the configuration. You will still need to create individual Windows services for each machine.

An example multiple machine ini file would look like :

Code: Select all

env=VBOX_USER_HOME=
env=VBOXGUI="C:\Program Files\Sun\xVM VirtualBox\virtualbox.exe"
env=VBOXHEADLESS="C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe"
env=VBOXWEBSRV="C:\Program Files\Sun\xVM VirtualBox\vboxwebsrv.exe"
env=VBOXMANAGE="C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe"
env=VBOX_PROG="C:\Program Files\Sun\xVM VirtualBox\"
env=VBOX_BASE="d:\vbox\"
env=VBOX_MACHINES="d:\vbox\machines"
env=VBOX_VDI="d:\vbox\VDI"
env=VBOX_MACHINE1=vbox_linsrv

debug=0
debug_out=>d:\vbox\VDI\VBOX.log

[VBOX_MACHINE1]
startup=%VBOXHEADLESS% -startvm VBOX_MACHINE1
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm VBOX_MACHINE1 savestate

[VBOX_MACHINE2]
startup=%VBOXHEADLESS% -startvm VBOX_MACHINE2
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm VBOX_MACHINE2 savestate
Then create two windows services with Windows Service Commander:

Use this command line for machine 1:

Code: Select all

c:\Program Files\srvstart\srvstart.exe svc VBOX_MACHINE1 -c "c:\Program Files\srvstart\srvstart.ini"
And this command line for machine 2:

Code: Select all

c:\Program Files\srvstart\srvstart.exe svc VBOX_MACHINE2 -c "c:\Program Files\srvstart\srvstart.ini"
And so on......
teelittle
Posts: 1
Joined: 18. Mar 2009, 14:08

strange error (was:Re: HOWTO - VBox as a service (srvstart.e

Post by teelittle »

Thanks a lot, rasker, for the detailed explanation and also the other HOWTOs showing how to do the same thing worse ;-)
All these documents gave me a lot better understanding about what's going on in my OS concerning services!

However, after reading your instructions and customizing the .ini file, I first wanted to dry test the srvstart.exe command, and got the following error message (which I think signals an internal error and is not caused by a misconfiguration - I am extremely confused by that D:\Home\Author\ path name):

Code: Select all

C:\Programme\srvstart> srvstart.exe svc ENTRY_FOSWIKI -c "C:\Programme\srvstart\foswiki-srvstart.ini"
ERROR: Exception 7 trapped in source file 'D:\Home\Author\srvstart.v110\dll\CmdRunner.cpp' line 296 
ERROR: Class 'CmdRunner' method 'CmdRunner' 
An internal error has occurred.
I am running Windows Server 2003 (German, hence "Programme" in path names) - is this old srvstart.exe suitable for this version of Windows Server?
FYI, here is my foswiki-srvstart.ini which is referenced by abovementioned srvstart.exe command line:

Code: Select all

# C:\Programme\srvstart\foswiki-srvstart.ini
# 
# This is the ini file for SRVSTART 
# to start the Virtualbox VM which contains 
# a Foswiki installation on Debian GNU/Linux 5.0 "Lenny" 

# The Windows service can be called anything you want.

# The srvstart commandline should refer to the [] section(s) 
# in this file exactly (case sensitive)  

# *****   GLOBAL OPTIONS   *****
#   Global options apply to all services managed by that ini file.
env=VBOXGUI="C:\Programme\Sun\xVM VirtualBox\virtualbox.exe"
env=VBOXHEADLESS="C:\Programme\Sun\xVM VirtualBox\vboxheadless.exe"
env=VBOXWEBSRV="C:\Programme\Sun\xVM VirtualBox\vboxwebsrv.exe"
env=VBOXMANAGE="C:\Programme\Sun\xVM VirtualBox\VBoxManage.exe"
env=VBOX_PROG="C:\Programme\Sun\xVM VirtualBox\"
env=VBOX_BASE="d:\VirtualBox\"
env=VBOX_MACHINES="d:\VirtualBox\machines"
env=VBOX_VDI="d:\VirtualBox\HardDisks"
env=VBOX_MACHINE1=Foswiki
env=STDERR="c:\windows\system32\stderr.exe"

# ***  Startup Options  ***
# STARTUP_DELAY=seconds
#    How long SRVSTART waits before reporting a "started" status 
#    to the NT Service Control Manager
# SRVSTART waits this number of seconds before reporting to the 
# Windows NT Service Control Manager that the service has started.
# Use this option if the command takes a long time to initialise 
# (default zero).
startup_delay=15 

# *****  SERVICE DEFINITION  *****
#   A single instance of SRVSTART can manage multiple individual 
#   services of it's own.
#   This is comparable to the way the windows svchost does things.
#   (duplicate the following for each service you want to run)

[ENTRY_FOSWIKI] 

# the command to start the virtual machine 
startup=%VBOXHEADLESS% -startvm %VBOX_MACHINE1%

# the command to stop the virtual machine
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm %VBOX_MACHINE1% savestate

#set to 1 for more debug messages from srvstart (note: not from virtualbox) 
debug=0

#point the debug file somewhere (note the > to overwrite an older log file) 
debug_out=>d:\vbox\VDI\d:\vbox\VBOX_LINUX.log 
Graham Norris
Posts: 12
Joined: 17. Mar 2009, 01:12

Re: strange error (was:Re: HOWTO - VBox as a service (srvstart.e

Post by Graham Norris »

teelittle wrote:I am extremely confused by that D:\Home\Author\ path name
That shows you the name of the C++ source file, and the line in it where the error occurred (the path shown is where from it was compiled - nothing to do with your machine). It is only useful to someone who has the source file. Although it doesn't directly help you, it is more useful than the supposedly user-friendly alternative sometimes employed: "An error has occurred" with no clue for anyone where it went wrong (been dealing with a bunch of those today on something else!)
a3ot
Posts: 2
Joined: 21. Mar 2009, 05:03

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by a3ot »

Try running the srvstart command line from the console as follows to debug your problems:
srvstart.exe cmd VBOX_MACHINE -d 1 -c "C:\Program Files (x86)\svstart\VBOXMACHINE.srvstart.ini"

After seeing the debug errors I realized that the last line of the example configuration file given above doesn't work, and svstart will not run on my system without a startup_dir configured as follows:
NO quotes, environment variables, or spaces!
startup_dir=c:\vbox

Also check out Nick Rozanski's site for the source code to srvstart for further debugging.

after making these changes everything works now.

Thanks for the tutorial!
-a3ot
rasker
Posts: 32
Joined: 6. Mar 2009, 15:27

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by rasker »

Hi all,

Sorry for not getting back to you sooner.

@teelittle - I haven't seen that particular error myself which is odd because I thought I had seen them all :) Perhaps it is caused by the line debug_out=>d:\vbox\VDI\d:\vbox\VBOX_LINUX.log, which should be debug_out=>d:\vbox\VDI\VBOX_LINUX.log? Try it with the debug lines commented out.
Google 'win32 error 7' for details of the actual error. MSDN says ERROR_ARENA_TRASHED - The storage control blocks were destroyed which does not shed any light on it for me.

Unfortunately Graham is right, it's a path from the developers machine. The only part of the error that is useful is the exception number which is a win32 exception.

@all - I am interested in what you guys are seeing when you shutdown your machines. Does it look like srvstart is doing the right thing?

Corrections to the original post:

1) Fixed paste error : debug_out=>d:\vbox\VDI\d:\vbox\VBOX_LINUX.log to debug_out=>d:\vbox\VDI\VBOX_LINUX.log
2) removed STDERR env. variable, not used.
a3ot
Posts: 2
Joined: 21. Mar 2009, 05:03

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by a3ot »

@all - I am interested in what you guys are seeing when you shutdown your machines. Does it look like srvstart is doing the right thing?
My vm seems to save state when I shut the machine down. I'm planning on using the ACPI shutdown as well, but everything is working fine as is except for some well known problems running FreeBSD 7.1 under VirtualBox that I've run into.
For whatever reason I've found the solution outlined on this page to be much easier to implement and debug than the one posted as a sticky on the top of the forum.
--a3ot
hanoirocks
Posts: 14
Joined: 23. Mar 2009, 08:08

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by hanoirocks »

Anybody have success with this on Vista as a host?
Vista has different pathing for the user accounts IE:

'C:\Documents and Settings\username" is different on Vista, it's "C:\Users\username\.Virtualbox"

Here's my config

env=VBOXGUI="C:\Program Files\Sun\xVM VirtualBox\virtualbox.exe"
env=VBOXHEADLESS="C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe"
env=VBOXWEBSRV="C:\Program Files\Sun\xVM VirtualBox\vboxwebsrv.exe"
env=VBOXMANAGE="C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe"
env=VBOX_PROG="C:\Program Files\Sun\xVM VirtualBox\"
env=VBOX_BASE="f:\VBOX\"
env=VBOX_MACHINES="f:\VBOX\Machines"
env=VBOX_VDI="f:\VBOX\HardDisks"
env=VBOX_MACHINE1=Windows7
startup_dir=d:\vbox

[Windows7]
startup=%VBOXHEADLESS% -startvm Windows7
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm Windows7 savestate
debug=1
debug_out=>f:\VBOX\HardDisks\Windows7.log

My service account info is as such: c:\Program Files\srvstart\srvstart.exe svc Windows7 -c "c:\Program Files\srvstart\srvstart.ini"


Here is the error log:

SRVSTART: 2009/03/22 23:25:09 INFORMATION severity=0 thread=5008 source=D:\Home\Author\srvstart.v110\exe\exe.cpp line=322 text=SRVSTART version 1.10 Copyright (C) 1998 - 2000 Nick Rozanski (Nick@Rozanski.com) (Distributed under the terms of the GNU General Public License as published by the Free Software Foundation)
SRVSTART: 2009/03/22 23:25:09 INFORMATION severity=0 thread=5008 source=D:\Home\Author\srvstart.v110\exe\exe.cpp line=324 text=To hide the startup message run SRVSTART with switch -d 0
SRVSTART: 2009/03/22 23:25:10 ERROR severity=0 thread=5008 source=D:\Home\Author\srvstart.v110\dll\CmdRunner.cpp line=1444 text=getProcessStatus(): command failed with exit code -2135228415
SRVSTART: 2009/03/22 23:25:10 ERROR severity=0 thread=5008 source=D:\Home\Author\srvstart.v110\dll\CmdRunner.cpp line=1130 text=watchCommand: process has finished with error
rasker
Posts: 32
Joined: 6. Mar 2009, 15:27

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by rasker »

@hanoirocks - this seems to be the large minus number error noted in the error codes section. (BTW, I added the number you get to that line, thanks). I'm not too familiar with Vista tbh but does it have an option to set the service to interact with the desktop? It's a checkbox on XP.
etasse
Posts: 1
Joined: 24. Mar 2009, 21:50
Primary OS: MS Windows XP
VBox Version: OSE other
Guest OSses: XP,Ubuntu

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by etasse »

Moderators, please 'sticky' this thread.
LesDes
Posts: 66
Joined: 23. Oct 2007, 09:53
Location: London

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by LesDes »

I've spent several hours trying to get this to work without any luck. Any suggestions would be welcome.

I've played around with the “startup_dir=” and got different results but still it fails.

For some paths I enter I get the large negative number error while for others I get the error:

SRVSTART: 2009/04/05 02:57:45 ERROR severity=0 thread=984 source=D:\Home\Author\srvstart.v110\dll\CmdRunner.cpp line=1334 text=createProcess(): failed to start process '"C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe" -startvm Mail', error=267

If I extract the command part of that error:

"C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe" -startvm Mail

and paste it into a command window it runs!

Error 267 is listed as “The directory name is invalid.” Which directory? My command file currently consists of:

env=VBOXGUI="C:\Program Files\Sun\xVM VirtualBox\virtualbox.exe"
env=VBOXHEADLESS="C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe"
env=VBOXWEBSRV="C:\Program Files\Sun\xVM VirtualBox\vboxwebsrv.exe"
env=VBOXMANAGE="C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe"
env=VBOX_PROG="C:\Program Files\Sun\xVM VirtualBox\"
env=VBOX_BASE="d:\"
env=VBOX_MACHINES="D:\VMMachines"
env=VBOX_VDI="F:\VMs"
env=VBOX_MACHINE1=Mail
startup_dir="C:\Program Files\Sun\xVM VirtualBox"

[Mail]
startup=%VBOXHEADLESS% -startvm Mail
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm Mail savestate
debug=1
debug_out=>c:\temp\Mail.log
=================

One other question: What is the significance of "env=" lines that are not referenced? Are they doing anything?
Les
LesDes
Posts: 66
Joined: 23. Oct 2007, 09:53
Location: London

Re: HOWTO - virtualbox as a service on Windows (srvstart.exe)

Post by LesDes »

Found the problem. Looks like I did not re-copy the xml file to the Local Service folder.

The control file is now:

--------------
env=VBOXHEADLESS="C:\Program Files\Sun\xVM VirtualBox\vboxheadless.exe"
env=VBOXMANAGE="C:\Program Files\Sun\xVM VirtualBox\VBoxManage.exe"

[Mail]
startup=%VBOXHEADLESS% -startvm Mail
shutdown_method=command
shutdown=%VBOXMANAGE% controlvm Mail savestate
debug=0
debug_out=>c:\temp\Mail.log
--------------

Whether the stopping of the service shuts down the VM properly I'm not so sure. I tested it by having FireFox open with two tabs. Normally when shutting down it would pop up with an option to save the tabs - and this does not happen.

Stopping the service opens a command window that counts quickly to to 100% and then RDP gives an error that it has lost contact. FF does not detect that the VM is closing.
Les
Post Reply