#! /bin/sh
# Copyright (c) 1995-2000 SuSE GmbH Nuernberg, Germany.
# Copyright (c) 2001 IBM
#
# Author: Kurt Garloff <feedback@suse.de>
# Author: Egan Ford <egan@us.ibm.com
#
# init.d/pbs_mom
#
#   and symbolic its link
#
# /usr/sbin/rcpbs_mom
#
# System startup script for the nessus backend nessusd
#
### BEGIN INIT INFO
# Provides: pbs_mom
# Required-Start: $remote_fs $syslog
# Required-Stop:  $remote_fs $syslog
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    Start pbs_mom to allow XY and provide YZ.
### END INIT INFO

if [ -r /etc/rc.config ]
then
	. /etc/rc.config
fi
if [ -r /etc/sysconfig/xcat ]
then
	. /etc/sysconfig/xcat
fi

# Determine the base and follow a runlevel link name.
base=${0##*/}
link=${base#*[SK][0-9][0-9]}

BASE_PBS_PREFIX=/opt/torque

ARCH=$(uname -m)
AARCH="/$ARCH"

if [ -d "$BASE_PBS_PREFIX$AARCH" ]
then
	PBS_PREFIX=$BASE_PBS_PREFIX$AARCH
else
	PBS_PREFIX=$BASE_PBS_PREFIX
fi

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num><num>
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status
. /etc/rc.status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

case "$1" in
    start)
	if [ -r /etc/security/access.conf.BOOT ]
	then
		cp -f /etc/security/access.conf.BOOT /etc/security/access.conf
	fi
	echo -n "Starting PBS Mom: "
	startproc $PBS_PREFIX/sbin/pbs_mom -r
	rc_status -v
	;;
    stop)
	echo -n "Shutting down pbs_mom"
	killproc pbs_mom
	rc_status -v
	;;
    restart)
	## Stop the service and regardless of whether it was
	## running or not, start it again.
	$0 stop
	$0 start

	# Remember status and be quiet
	rc_status
	;;
    status)
	echo -n "Checking for pbs_mom: "
	checkproc pbs_mom
	rc_status -v
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
	;;
esac
rc_exit
