#!/bin/sh
#
# webs		Start and stop GoAhead WebServer.                    
#
# description: Web Server        

# Author	Chan Yoon Jung, <jucys@seyeon.co.kr>

# processname: webs                                                            


# Source function library.
. /etc/rc.d/init.d/functions

[ -x /usr/sbin/webs ] || exit 0

RETVAL=0

# See how we were called
case "$1" in
 start)
 	echo -n "Starting Web Server: "
	/usr/sbin/webs

	for a in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 
        do
#		echo -n "$a"
		sleep 1
		if [ -e /var/run/webs.pid ]; then
			break
		fi
		sleep 1
        done

	RETVAL=$?
	if [ $RETVAL -eq 0 ]; then
		echo "[  OK  ]"
	else
		echo "[FAILED]"
	fi
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/webs
	;;
 stop)
 	echo -n "Shutting down Web Server: "
#	killproc webs
#	ps -eo pid,cmd | grep "\ webs\ ph" | awk 'NR == 3 {print $1}' | xargs kill -9 >& /dev/null
	kill `/bin/cat /var/run/webs.pid`

	for a in 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 24 25 26 27 28 29
	do
#		echo -n "$a"
		sleep 2
                if [ ! -e /var/run/webs.pid ]; then
			break
                fi
		sleep 2
                if [ ! -e /var/run/webs.pid ]; then
			break
                fi
        done

	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/webs
	if [ $RETVAL -eq 0 ]; then
		echo "[  OK  ]"
	else
		echo "[FAILED]"
	fi
 	;;
 restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
 *)
 	RETVAL=1	
 	;;
esac

exit $RETVAL 

