#!/bin/bash
# chkconfig: 2345 85 15
# description: WebShield runs filtering proxy servers for various protocols
# Copyright (C) 2004 Networks Associates Technology Inc. All rights reserved.
#
# WebShield(TM)
# TAG=LINUX
#
if [ -f $NETAWSS/.profile.vars ]; then 
    . $NETAWSS/.profile.vars 
else 
    . /var/NAIENV/.profile.vars 
fi 
PATH=$wsPATH:$PATH

. message_functions.bash	# message localisation


service_status()
{
    o=''
    [[ $1 == stop ]] && o='r'
    list=$(ls -d$o ${WSMGMT}/webshieldservices.d/*)
    for f in $list
    do
    	if [ -x ${f} ]
    	then
	    ReportProgress _TR_ "ws-serv-conf" $"WebShield service %s %s" "${f##*/}" "$1"
	    out=$(${f} ${1} 2>&1)
	    if [ $? != 0 ]
	    then
		name=`basename $f`
		logger -t ws-services error ${1}ing service ${f##*/}: $out
		RET=1
	    fi
	    ${out:+printf '%s\n' "$f:" "$out"}
    	fi
    done

}
start() 
{
    if [ -f /.webshield_running ]
    then
	/usr/bin/logger "Webshield started without a shutdown"
    fi
    service_status start

    touch /var/lock/subsys/ws-appliance-services
    touch /.webshield_running

    return 0
}

stop() 
{
    service_status stop
    rm -f /var/lock/subsys/ws-appliance-services
    rm -f /.webshield_running
    return 0
}

usage() 
{
    echo "Usage: ws-appliance-services start|stop|restart|reload"
    exit 1
}

case $1 in
    start) start;;
    stop) stop;;
    restart) stop;start;;
    reload)
	if [[ -f /var/lock/subsys/webshield ]]
	then service_status reload
	else stop; start
	fi
	;;
    *) usage;;
esac

exit $RET
