#!/bin/sh

#
# COPYRIGHT    2001
# THE REGENTS OF THE UNIVERSITY OF MICHIGAN
# ALL RIGHTS RESERVED
#
# Permission is granted to use, copy, create derivative works
# and redistribute this software and such derivative works
# for any purpose, so long as the name of The University of
# Michigan is not used in any advertising or publicity
# pertaining to the use of distribution of this software
# without specific, written prior authorization.  If the
# above copyright notice or any other identification of the
# University of Michigan is included in any copy of any
# portion of this software, then the disclaimer below must
# also be included.
#
# THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION
# FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY
# PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY O
# MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING
# WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
# REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE
# FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR
# CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING
# OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN
# IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGES.
#

# stop an apv subsystem (listener or archiver)

KBS=./kbs
WHICH=none


usage() {
	echo "usage:	$0 [-l | -a]
	-l to stop listener subsystem
	-a to stop archiver subsystem
	(exactly one option must be specified)"
	exit 1;
}

date >>apv.log
echo + $0 $* >>apv.log

if [ `id -u` != '0' ]; then
	echo "You must be root to run this script."
	exit 1
fi

while [ -n "$1" ]; do
	case $1 in
		-a)	if [ $WHICH = listener ]; then usage; fi;
			WHICH=archiver;;
		-l)	if [ $WHICH = archiver ]; then usage; fi;
			WHICH=listener;;
		-*|*)	usage;;
	esac
	shift
done
if [ $WHICH != listener -a $WHICH != archiver ]; then
	usage
fi

if [ $WHICH = listener ]; then

	echo "Stopping listener..."
	$KBS -INT '/sh ./pilot.sh'
	$KBS -INT '/tclsh ./pilot.tcl'
	$KBS -INT '/sh ../listen/listen.sh'
	$KBS -INT '/util/logmonitor /var/log/pilot.log'
	$KBS -INT '/util/logmonitor /var/log/listen.log'
	$KBS -INT '/listen/listen -f /'
	$KBS -INT '../dump/pkt_dump'
	$KBS -INT '/sh ../dump/pkt_dump.sh'
	/sbin/umount -f /mfs

else 

	echo "Stopping archiver..."
	$KBS -INT '/sh ./archiver.sh'
	$KBS -INT '/perl ./archiver.pl'
	$KBS -INT '/util/logmonitor /var/log/archiver.log'
fi

exit 0
