#!/bin/sh
#
# Apache start/stop script
# 
# Written by Ron Record (rr@sco.com)
# Modified 30-Jun-98 for use in conjunction with the apachectl script
# provided in Apache 1.3.x
#
# Modified 2001-03-15 by Allan Clark (allanc@sco.com) based on Rainer Flucke's
# (rainerf@sco.com) suggestions for UW& NSC installation.
#
# Usage: 
# apache [ start|stop|restart|fullstatus|status|graceful|enable|disable|help|up ]
#

APACHEHOME=/usr/lib/apache
PATH=${APACHEHOME}/bin:/bin:/usr/bin:/etc
SCRIPT=`basename $0`
RCSCRIPT="/etc/rc2.d/S91apache /etc/rc2.d/U91apache /etc/rc2.d/K07apache"
HTTPD=${APACHEHOME}/bin/httpd

# change the following if you changed the default PidFile definition in
# your Apache conffile (httpd.conf)
# only relevant on NSC with keepalive configured for Apache
PIDFILE=${APACHEHOME}/httpd.pid

export PATH SCRIPT RCSCRIPT HTTPD PIDFILE


http_enable() {
        if [ -h $RCSCRIPT ] ; then
                echo "$HTTPD is already enabled."
        else
                echo "Enabling $HTTPD ... \c"
		for i in ${RCSCRIPT}; do rm -f ${i}; ln -s /etc/apache ${i}; done
                echo "done."
        fi
	return 0
}

http_disable() {
        echo "Disabling $HTTPD ... \c"
	for i in ${RCSCRIPT}; do rm -f ${i}; done
        echo "done."
	return 0
}

# main()

cd /

case $1 in

enable)
        http_enable
        ;;

disable)
        http_disable
        ;;

start | up) 
	# use the presence of "/usr/bin/cluster" to check whether it's a
	# UnixWare 7 NonStop Cluster or a standard UW7 system
	# Note addition of "up" action as well.

	if [ -x /usr/bin/cluster ]
	then 
		STARTNODES=`/usr/bin/cluster` 
		echo "Apache STARTNODE: $STARTNODES" 
		for i in $STARTNODES 
		do 
			/sbin/spawndaemon -i node_list -n 1 -F $i -Z F_node -r ka_apache 
		done 
	else 
		apachectl startssl
	fi 
	;; 

stop) 
	if [ -x /usr/bin/cluster ]
	then
		STOPNODES=`/usr/bin/cluster` 
		echo "Apache STOPNODE: $STOPNODES" 
		for i in $STOPNODES 
		do 
			NODE_PIDFILE="${PIDFILE}.${i}" 
			if [ -s $NODE_PIDFILE ] 
			then 
				read pid < $NODE_PIDFILE 
				/sbin/spawndaemon -k -p $pid 
				rm -f $NODE_PIDFILE
				sleep 2 
			fi 
		done 
	else
		apachectl stop 
	fi
	;; 

*)
	apachectl $*
        ;;

esac

exit $?
