#!/bin/sh

# A script to restart GNS or MSF daemons: apache, npdd and sda or sdu
# If input flag -s, restart npdd only
# If input flag -a, restart npdd, apache and sda
# If input flag -u, restart npdd , apache and sdu
# If input flag -b, restart both sdad and sdud with npdd and apache

LD_LIBRARY_PATH=/usr/local/gwa/lib:/usr/local/lib:/usr/ucblib
export LD_LIBRARY_PATH

if [ "$1" = "-s" ] ; then
	SETONLY=1
	shift
fi

PATH=/usr/local/gwa/bin:.:$PATH

# Temporarily needed by Rsm:
rm /usr/local/gwa/share/npdd/rescounter.dat
rm /usr/local/gwa/share/npdd/resrequest.dat

# If GNS, restart sda

if [ "$1" = "-a" -o "$1" = "-b" ] ; then	## GNS
	killproc sda
	/usr/local/gwa/bin/sdad
#	/usr/local/gwa/globecom/globalsale/sda/startIsAlive.sh &
	/usr/local/gwa/bin/startIsAlive.sh &
fi

# If MSF, restart sdu

if [ "$1" = "-u" -o "$1" = "-b" ] ; then	## MSF
	killproc sdu
	/usr/local/gwa/bin/sdud
fi

killproc Npdd
/usr/local/gwa/bin/Npdd

# Start up the Apache daemon
		echo ""
		echo Restarting httpd
		/etc/init.d/httpd stop 2> /dev/null
		/etc/rc.d/init.d/httpd stop 2> /dev/null
		sleep 2
		/etc/init.d/httpd start 2> /dev/null
		/etc/rc.d/init.d/httpd start 2> /dev/null
		exit