#!/bin/sh
#
# moab          This shell script takes care of starting and stopping
#               the TORQUE resource manager and Moab Workload Manager.
#
# description: TORQUE is a scalable resource manager which manages jobs in
# 	           cluster environments. Moab is a cluster scheduler which uses
#	             TORQUE to schedule jobs on that cluster.
#

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Read in the command arguments
case "$1" in
  start)
	# Start TORQUE services first...
	
	echo -n $"Starting TORQUE services: "
	daemon /usr/local/torque/sbin/pbs_mom
	daemon /usr/local/torque/sbin/pbs_server
	echo

	# Next start Moab Workload Manager...
	echo -n $"Starting Moab Workload Manager: "
	daemon su -l -s /bin/sh root -c "/opt/moab/sbin/moab"
	echo
	;;

  stop)
	# Stop Moab first...

	echo -n $"Shutting down Moab Workload Manager: "
	killproc moab
	echo

	echo -n $"Shutting down TORQUE services: "
	killproc pbs_server
	echo
	killproc pbs_mom
	echo
	;;

  restart)
	$0 stop
	$0 start
	;;
  *)
	echo $"Usage: moab {start|stop|restart}"
	exit 1
esac

exit 0

