#! /bin/sh
# 
### BEGIN INIT INFO
# Provides: vmware HP Failover Manager
# Required-Start: $network $syslog 
# Should-Start: sshd
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the Oracle database
### END INIT INFO
 
# Here we finally get to do the real work.
case "$1" in
  start)
    echo
    echo "Starting HP Failover Manager in VM Player......"
    echo
    /usr/bin/vmrun -T player start /home/oracle/vmware/FOM/FOMconverted.vmx nogui
    exit $?
    ;;
  stop)
    echo
    echo "Stopping HP Failover Manager in VM Player......"
    echo
    /usr/bin/vmrun -T player stop /home/oracle/vmware/FOM/FOMconverted.vmx nogui
    exit $?
    ;;
  check)
    echo
    echo "Status of HP Failover Manager....."
    echo
    noofvm=`/usr/bin/vmrun -T player list | grep VMs: | awk '{print($4)}'`
    if [ "$noofvm" = "1" ]; then
      exit 0
    else    
      exit 1 
    fi 
    ;;
  clean)
    echo
    echo "Status of HP Failover Manager....."
    echo
    /usr/bin/vmrun -T player stop /home/oracle/vmware/FOM/FOMconverted.vmx nogui
    noofvm=`/usr/bin/vmrun -T player list | grep VMs: | awk '{print($4)}'`
    if [ "$noofvm" = "0" ]; then
      exit 0
    else    
      exit 1 
    fi 
    ;;
  status)
    echo
    echo "Status of HP Failover Manager....."
    echo
    noofvm=`/usr/bin/vmrun -T player list | grep VMs: | awk '{print($4)}'`
    if [ "$noofvm" = "1" ]; then
      exit 0
    else    
      exit 1 
    fi 
    ;;
  restart)
    ## Stop the service and regardless of whether it was
    ## running or not, start it again.
    $0 stop
    $0 start
    exit $?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|check|clean}"
    exit 1
esac
