#!/bin/sh
#
# pbs_sched	This script will start and stop the PBS Scheduler
#
# chkconfig: 345 85 85
# description: TORQUE/PBS is a batch versatile batch system for SMPs and clusters
#
# processname: pbs_sched
#
### BEGIN INIT INFO
# Provides: pbs_sched
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Short-Description: The Torque scheduler
# Description: The Tera-scale Open-source Resource and QUEue manager
#              provides control over batch jobs and distributed
#              computing resources. It is an advanced open-source
#              product based on the original PBS project and
#              incorporates the best of both community and
#              professional development.
### END INIT INFO
#
# Source the library functions
. /etc/rc.d/init.d/functions

PBS_DAEMON=/usr/sbin/pbs_sched
PBS_HOME=/var/spool/torque
export PBS_DAEMON PBS_HOME

if [ -f /etc/sysconfig/pbs_sched ];then
   . /etc/sysconfig/pbs_sched
fi

# let see how we were called
case "$1" in
	start) 
		gprintf "Starting TORQUE Scheduler: "
		status pbs_sched 2>&1 > /dev/null
		RET=$?
		[ $RET -eq 0 ] && gprintf "pbs_sched already running" && success && echo && exit 0

		daemon $PBS_DAEMON -d $PBS_HOME
		RET=$?
		[ $RET -eq 0 ] && touch /var/lock/subsys/pbs_sched
		echo
		;;
	stop)
		gprintf "Shutting down TORQUE Scheduler: "
		status pbs_sched 2>&1 > /dev/null
		RET=$?
		[ ! $RET -eq 0 ] && gprintf "pbs_sched already stopped" && success && echo && exit 0

		killproc pbs_sched
		RET=$?
		rm -f /var/lock/subsys/pbs_sched
		echo
		;;
	status)
		status pbs_sched
		RET=$?
		;;
	restart)
		$0 stop
		$0 start
		;;
	reload) 
		gprintf "Reloading pbs_sched: "
		killproc pbs_sched -HUP
		RET=$?
		echo
		;;
	*)
		gprintf "Usage: pbs_sched {start|stop|restart|status}\n"
		exit 1
esac
exit $RET
