-- MikeGore - 2014-06-04
#!/bin/bash # # Should-Start: vmware # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Description: VMware VM image starter # =========================================== # Author: Mike Gore 27 May 2014 # What: This script will run a single VM as a service # Uses: VMware Workstation 8,9,10 # =========================================== # vmrun command VMRUN=/usr/bin/vmrun NAME=`basename $0` # =========================================== # Define the full pathname of your VM here VM= # Example: # VM=/home/cscf-adm/vmware/win7.vmx # =========================================== # Check that VM has been defined if [ -z "$VM" ] then echo "You must define VM" echo "Example:" echo " VM=\"/home/cscf-adm/vmware/win7.vmx\"" echo "Note: This is the full name and path to the VM" exit 1 fi # Check that the VMRUN command exists if [ ! -f "$VMRUN" ] then echo "$VMRUN command is missing" exit 1 fi case $1 in start) STATS=`"$VMRUN" -T ws list "$VM" 2>/dev/null | grep "$VM"` if [ -n "$STATS" ] then echo "$STATS is already running" exit 1 fi echo "Starting $VM" "$VMRUN" -T ws start "$VM" nogui ;; stop) echo "Stopping $VM" "$VMRUN" -T ws stop "$VM" soft ;; restart-force) echo "Restarting, with hard option, $VM" "$VMRUN" -T ws stop "$VM" hard ;; restart) echo "Restarting $VM" service "$NAME" stop service "$NAME" start ;; status) "$VMRUN" -T ws list "$VM" ;; install) if [ -f /etc/init.d/"$NAME" ] * *service vmware restart* - restarts VM then echo "$NAME already exists in /etc/init.d" echo "If you are SURE this is correct run $NAME remove first" exit 1 fi # Install Service chmod 755 "$NAME" cp -p "$NAME" /etc/init.d # If it did exist remove it first update-rc.d -f "$NAME" remove # Install Srevice update-rc.d "$NAME" defaults 95 01 ;; remove) service "$NAME" stop update-rc.d -f "$NAME" remove ;; *) echo "usage: `"$NAME"` {start|stop|restart|restart-force|status|install|remove}" ;; esac