#!/bin/sh
#
# stopserver - Shell Script which will stop the PxPlus WebServer
#
# Copyright 2001 Best Software Canada Ltd.
# Ver 1.0 - GD 8/1/1999
# Ver 1.1 - GD 7/12/2001, Corrected, would not stop under Linux OS's

CONFIGWEB=$0
WEBDIR=`dirname $CONFIGWEB`
if [ $WEBDIR = "." ]
then 
	WEBDIR=`pwd`
else 
	WEBDIR=$WEBDIR
fi

rm -rf $WEBDIR/stopserver.tmp 2>&1 >/dev/null
rm -rf $WEBDIR/stopserver.dat 2>&1 >/dev/null

ps -eo "pid args" | grep $WEBDIR >$WEBDIR/stopserver.tmp
sort -k 3 <$WEBDIR/stopserver.tmp >$WEBDIR/stopserver.dat
rm -rf $WEBDIR/stopserver.tmp 2>&1 >/dev/null

while read line
do
	PROCESSID=`echo $line | cut -d " " -f1`
	COMMAND=`echo $line | cut -d " " -f2`
	PROGRAM=`echo $line | cut -d " " -f3`

	if [ "$COMMAND" = $WEBDIR/pxplus ]
	then
		if [ "$PROGRAM" = "*web/webserv" ]
		then
			kill -2 $PROCESSID 2>/dev/null
			sleep 1
		fi
		if [ "$PROGRAM" = "*web/websport" ]
		then
			kill -2 $PROCESSID 2>/dev/null
			sleep 1
		fi
		if [ "$PROGRAM" = "*web/webstask" ]
		then
			kill $PROCESSID 2>/dev/null
		fi
	fi
done < $WEBDIR/stopserver.dat

rm -rf $WEBDIR/stopserver.dat 2>&1 >/dev/null

echo "PxPlus-WebServer: Stopped."

exit 0
