VMware Player - Running as a Service

Vmware Server is the correct tool for running a VM in the background, not Vmware Player.


Sorry for the late responce with this. I was trying to figure this out today. I came across this answer, figured I let SF know.

You can actually ...

  • Add this to your VMX config file to set VMWare Player not show the UI:

    msg.noOk = "TRUE"

  • Get instsrv.exe from a Windows Server Resource Kit to create your own service

  • On Startup have a batch file call the service you just made

Step-by-step instructions can be found here:

http://research.stowers-institute.org/dct/docs/admin/VMwarePlayerService.htm


I know this is an old question, but I searched all over the internet for a solution to this and I couldn't find anything quite as comprehensive as what I'd like to share.

Yes, it's possible to use vmware player as a service for Linux (there's a separate answer for Windows); it's easy and there's no reason I can think of not to do it. It's especially great for hosting a headless server from a headless server.

The other VMware-oriented choice, VMware Server, is deprecated and the only other $0 choice I know of is VirtualBox. If you like that better than VMWare Player, more power to you, but I know VMWare Player and I don't see a reason not to use a well-supported path to get what I want.

Presumably you'll want it to run under a non-root account and start up and shut down at the standard service startup/shutdown times. If that's the case, then here's how to configure it:

  • Get the daemon package (usually not installed by default):

    apt-get install daemon
    
  • Download VMware Player and VMware VIX from vmware.com and install them to get the VM engine and VIX's vmrun (command-line control of vm execution) binary.

  • Add the service to the startup by creating /etc/init.d/<vm_server_name>. It could look something like this:

    #! /bin/bash
    ### BEGIN INIT INFO
    # Provides:          vm_server_name
    # Required-Start:    $named $remote_fs $syslog
    # Required-Stop:     $named $remote_fs $syslog
    # Default-Start:     2 3 4 5
    # Default-Stop:      0 1 6
    # Short-Description: My Server VM
    # Description:       Virtual Machine instance of My Server
    ### END INIT INFO
    
    PATH=/sbin:/usr/sbin:/bin:/usr/bin
    VM="/path/to/vmx_file.vmx"
    USER_TO_RUN_UNDER="username"
    
    if [[ "$USER" == "$USER_TO_RUN_UNDER" ]]; then
      USER_FLAG=""
    else
      USER_FLAG="--user=$USER_TO_RUN_UNDER"
    fi
    
    case "$1" in
        start)
            daemon $USER_FLAG -- vmrun -T player start "$VM" nogui &>/dev/null &
            ;;
        stop)
            vmrun -T player suspend "$VM" &>/dev/null
            while [[ "$(vmrun -T player list | grep -o "$VM")" == "$VM" ]]; do
              sleep 1
            done
            ;;
        *)
            echo "Usage: $0 start|stop" >&2
            exit 3
            ;;
    esac
    
  • Make the script runnable:

    chmod a+x /etc/init.d/vm_server_name
    
  • Add the script to the standard linux service startup/shutdown runlevels. The numbers ensure that it is one of the last things started and the first to be shut down:

    update-rc.d vm_server_name defaults 99 01
    

Notes:

  • You'll probably need to 'sudo' all the commands as you're modifying root-owned files.
  • I put a loop in so that on shutdown the script doesn't return to the OS until it has completely suspended the guest OS. I don't know if that's needed or not, but it seemed like a good idea. It will definitely slow down shutdown of the host OS, but it is worth it in my opinion.
  • If you need to interact with the local GUI of the guest OS, suspend the server by running /etc/init.d/vm_server_name stop and then start it locally using the VMware player GUI. After finishing, suspend it and run /etc/init.d/vm_server_name start to start the headless instance again.