#! /bin/sh
# 
### BEGIN INIT INFO
# Provides: CMSAPPMQ ACFS folder share over NFS
# Required-Start: $network $syslog 
# Should-Start: sshd
# Required-Stop:
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the NFS serviceNFS serviceNFS serviceNFS service
### END INIT INFO
 
# Here we finally get to do the real work.
case "$1" in
  start)
    mountcmsappmq=`mount |grep cmsappmq`
    while [ "$mountcmsappmq" == "" ]
    do
        echo "Sleeping 2 seconds, cmsappmq not yet mounted..."
	sleep 2 
    	mountcmsappmq=`mount |grep cmsappmq`
    done
    chmod 777 /cmsappmq
    chmod 777 /clusfiles
    echo
    echo "Starting NFS Server......"
    echo
    /sbin/service nfs start
    exit $?
    ;;
  stop)
    echo
    echo "Stopping NFS Server......"
    echo
    /sbin/service nfs stop
    exit $?
    ;;
  check)
    echo
    echo "Status of HP Failover Manager....."
    echo
    nfsstat=`/sbin/service nfs status | grep nfsd | grep running`
    if [ -n "$nfsstat" ]; then
      exit 0
    else    
      exit 1 
    fi 
    ;;
  clean)
    echo
    echo "Stop and Cleanup NFS ....."
    echo
    /sbin/service nfs stop
    nfsstat=`/sbin/service nfs status | grep nfsd | grep running`
    if [ "$nfsstat" == "" ]; then
      exit 0
    else    
      exit 1 
    fi 
    ;;
  status)
    echo
    echo "Status of NFS Service....."
    echo
    nfsstat=`/sbin/service nfs status | grep nfsd | grep running`
    if [ -n "$nfsstat" ]; 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
