#!/bin/sh
# $Id$
#
# Description:	Startup/shutdown/restart script for Netscape
#		suitespot enterprise web servers
#
# Author:	High-Availability.Com Ltd
#

. /opt/HAC/bin/rsf.sh

# Location of web server home directory
HTHOME="/usr/netscape/suitespot"

# Enable startup of netscape web admin server
START_ADMIN=1

service=${RSF_SERVER:-'Netscape_enterprise_server'}
host="`uname -n`"
script="`basename $0`"
state=$1
attempts=${2:-'1'}

if [ ${attempts} -gt 3 ]; then
	dated_echo "Startup failed, aborting"
	exit ${RSF_ABORT}
fi

case "${state}" in

'start'|'stop')
	if [ ${START_ADMIN} -ne 0 ]; then
		${HTHOME}/${state}-admin
	fi

	elist=`/bin/ls -dA ${HTHOME}/https-*`

	for svc_script in ${elist}; do

		dated_echo "${svc_script} ${state} "

		# check for executable bit
		if [ -x "${HTHOME}/${svc_script}/${state}" ]; then
			# assume non-sh
			${HTHOME}/${svc_script}/${state}
			ret_stat=$?
		else
			sh ${HTHOME}/${svc_script}/${state}
			ret_stat=$?
		fi

		if [ ${ret_stat} -ne 0 ]; then
			dated_echo "${svc_script} failed, retrying"
			exit ${RSF_RESTART}
		fi

	done

	;;

'restart')
	$0 stop
	$0 start
	;;

*)
	echo "Usage: ${script} <start|stop|restart>"
	exit ${RSF_WARN}
	;;

esac

exit ${RSF_OK}
