#!/bin/sh
# $Id$
#
# Description:	Startup/shutdown script for Apache/NCSA compatible
#		web servers
#

#
# standard variables and functions
#
. /opt/HAC/bin/rsf.sh

service="HTTP_service"
# Location of web server home directory
HTHOME=/shared/www/httpd
# Location of httpd binary
HTTPD=${HTHOME}/htbin/httpd

script="$0"
state=$1
attempts=${2:-'1'}

# function for log mesg
dated_echo()
{
	date_now=`date +'%b %d %H:%M:%S'`
	echo "${date_now} `uname -n` ${script}[$$]: $*"
}

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

case ${state} in

'start')
	if [ -f "${HTTPD}" ]; then
		dated_echo "${service}: Starting httpd"
		${HTTPD} -d ${HTHOME}
		if [ $? -ne 0 ]; then
			dated_echo "${service}: ${HTTPD} failed, retrying"
			exit ${RSF_RESTART}
		fi
	fi
	;;

'stop')
	PID=`/usr/bin/ps -ef | grep ${HTTPD} | grep -v grep | awk '{print $2}'`
        if [ ! -z "$PID" ] ;  then
		dated_echo "${service}: Stopping httpd"
                /usr/bin/kill `cat ${HTHOME}/logs/httpd.pid` 1> /dev/null 2>&1
        fi
	;;

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

esac

exit ${RSF_OK}	# OK code (default)
