#!/bin/sh
#
# trqauthd	This script will start and stop the Torque Authorization Daemon
#
# chkconfig: 345 85 85
# description: TORQUE/PBS is a batch versatile batch system for SMPs and clusters
#
# processname: trqauthd
#
### BEGIN INIT INFO
# Provides: trqauthd
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Short-Description: The Torque client authorization daemon
# 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


# NOTE: customize these two variables as needed
PBS_DAEMON=/usr/sbin/trqauthd
PBS_HOME=/var/spool/torque

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

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

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

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