#!/sbin/sh
#
# Copyright (c) 2001 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident	"@(#)initspm	1.8	02/09/18 SMI"

APACHE_HOME=/opt/SUNWscvw
CONF_FILE=/opt/SUNWscvw/conf/httpd.conf
PIDFILE=/var/cluster/spm/httpd.pid
HTTPD=/usr/apache/bin/httpd
SCGUIEVENTD=/var/cluster/spm/bin/scguieventd

# Check to see if the Apache binary is there
if [ ! -f ${HTTPD} ]; then
	echo "NOTICE: To finish installing the SunPlex Manager, you must install the SUNWapchr and SUNWapchu Solaris packages and any associated patches. Then run '/etc/init.d/initspm start' to start the server."
	exit 0
fi

if [ ! -f ${CONF_FILE} ]; then
	exit 0
fi

case "$1" in
start)
	/bin/rm -f ${PIDFILE}
	cmd="startssl"
	cmdtext="starting"

	# test whether we are a cluster and start scguieventd if so
	/usr/sbin/clinfo > /dev/null 2>&1
	if [ $? = 0 ] ; then
	    ${SCGUIEVENTD} -d
	fi
	;;
restart)
	cmd="restart"
	cmdtext="restarting"
	# test whether we are a cluster and restart scguieventd if so
	/usr/sbin/clinfo > /dev/null 2>&1
	if [ $? = 0 ] ; then
	    /usr/bin/pkill -x -u 0 scguieventd
	    ${SCGUIEVENTD} -d
	fi
	;;
stop)
	cmd="stop"
	cmdtext="stopping"
	# test whether we are a cluster and stop scguieventd if so
	/usr/sbin/clinfo > /dev/null 2>&1
	if [ $? = 0 ] ; then
	    /usr/bin/pkill -x -u 0 scguieventd
	fi
	;;
*)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac

status=`${APACHE_HOME}/bin/apachectl $cmd 2>&1`

if [ $? != 0 ]; then
	echo "$status"
	exit 1
fi
exit 0
