#!/bin/sh
#
#ident  "@(#)sws_tp     2.4     96/10/08 SMI"
#
# Copyright (c) 1996 by Sun Microsystems, Inc.
#
# Sun Web Server start/stop script
# This script is generally in /etc/rc2.d
#
# Modify the variables below if you would like the script to work for
#  non-default locations.

SCRIPT_NAME=`basename $0`
SCRIPT_DIR=`dirname $0`

# If SCRIPT_DIR is not an absolute path name (i.e. it doesn't begin with a '/')
# then we try to find the absolute path name using 'pwd'.

case $SCRIPT_DIR in
/* )
	;;
 * )
	INVOKING_DIRECTORY=`/usr/bin/pwd`
	SCRIPT_DIR=$INVOKING_DIRECTORY/$SCRIPT_DIR
	;;
esac

BASEDIR=$SCRIPT_DIR/../..

CONF_DIR=$BASEDIR/etc/http
CONF_FILE=$CONF_DIR/httpd.conf

HTTPD_DIR=$BASEDIR/usr/lib
PID_DIR=$BASEDIR/var/http/tmp

PATH=/sbin:/usr/bin:/usr/sbin
export PATH

# Start/stop Sun Web Server

case "$1" in
'start')

    if [ -f $CONF_FILE ]; then
        $HTTPD_DIR/httpd -config $CONF_FILE -config_dir $CONF_DIR > /dev/null 2>&1&

        #$HTTPD_DIR/httpd -config_dir $CONF_DIR > /dev/null 2>&1&


    else
        echo "httpd not started, $CONF_FILE does not exist"
    fi

    ;;

'restart')

    if [ -f $PID_DIR/httpd.pid ]; then
        pid=`head -n 1 $PID_DIR/httpd.pid`
        ps -p $pid 2> /dev/null 1> /dev/null
        if [ $? -ne 0 ]; then
            echo httpd not restarted, httpd.pid file not valid
            exit
        fi

        if [ -z "`ps -p $pid|awk '{print $4}'|grep \"^httpd$\"`" ]; then
            echo httpd not restarted, pid incorrect
        else
            kill -HUP $pid 
            echo httpd restarted
        fi
    else
        echo httpd not restarted, httpd.pid file missing
    fi

    ;;

'stop')

    if [ -f $PID_DIR/httpd.pid ]; then
        pid=`head -n 1 $PID_DIR/httpd.pid`
        ps -p $pid 2> /dev/null 1> /dev/null
        if [ $? -ne 0 ]; then
            echo httpd not stopped, httpd.pid file not valid
            exit
        fi

        if [ -z "`ps -p $pid|awk '{print $4}'|grep \"^httpd$\"`" ]; then
            echo httpd not stopped, pid incorrect
        else
            kill $pid 
        fi
    else
        echo httpd not stopped, httpd.pid file missing
    fi

    ;;

*)
    echo "Usage: $SCRIPT_NAME { start | stop | restart }"
    ;;
esac
