#!/bin/sh
#
# Startup script for the InterScan httpd server.
#
# processname: vcagt
# chkconfig: 345 99 99
# description: Startup script for the InterScan httpd server.
BASE_NAME=ishttpd
DAEMON=/etc/iscan/$BASE_NAME
PKGONFILE=/etc/iscan/pkg/ISHTTPON
SUBSYS_DIR=/var/lock/subsys
SCRIPT_NAME=iscanhttpproxys
rc_done=""
rc_failed=""

if [ ! -f $PKGONFILE ] ; then
	exit 1
fi

#
# RL to detect if the target linux is SUSE
#
if [ -f /etc/SuSE-release ]; then
	DIS_TYPE=SuSE
fi

PKGON=`cat $PKGONFILE`

# Source function library.
. /etc/iscan/isfunctions	# isdaemon/iskillproc
if [ $DIS_TYPE = "SuSE" ] ; then
#    . /etc/rc.config
     dummy=1
else
    . /etc/rc.d/init.d/functions
fi

return=$rc_done

# See how we were called.
case "$1" in
  start)
	if [ $PKGON != "1" ] ; then
		exit 0
	fi
	cd /etc/iscan
	echo -n "Starting ${BASE_NAME}: "
	unset JP_FUNC   # clear
	/etc/iscan/getconf scan-configuration jp_func > /dev/null 2>&1
	if [ $? = 0 ] ; then
		if [ `/etc/iscan/getconf scan-configuration jp_func` = "no" ] ; then
			JP_FUNC="no"
			export JP_FUNC
		fi
	fi
	isdaemon ${DAEMON} || return=$rc_failed

	#touch $SUBSYS_DIR/$SCRIPT_NAME
	echo -e "$return"
	;;
  stop)
	echo -n "Shutting down ${BASE_NAME}: "
	iskillproc ${DAEMON} || return=$rc_failed

	#rm -f $SUBSYS_DIR/$SCRIPT_NAME
	echo -e "$return"
	;;
  status)
	if [ $DIS_TYPE = "SuSE" ] ; then
	    echo -n "Checking for service ${BASE_NAME}: "
	    checkproc ${DAEMON} && echo OK || echo No process
	else
	    status $BASE_NAME
	fi
	;;
  restart)
	$0 stop
	$0 start
	;;
  reload)
	echo -n "Reloading ${BASE_NAME}: "
	killproc $DAEMON -HUP
	echo
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reload|status}"
	exit 1
esac

test "$return" = "$rc_done" || exit 1
exit 0
