#!/bin/sh


# 
#  @(#)stop-diag	1.14 01/04/10
#
#  Copyright (c) 04/10/01 Sun Microsystems, Inc.  All Rights Reserved
#
#  @version 1.14 01/04/10 12:27:52
#


dirname=`/bin/dirname $0`
if [ -d $dirname ]; then
	## Set the I18N/L10N environment
	if [ -f $dirname/common.sh ]; then
		. $dirname/common.sh
	fi
else
	## this will be a simple echo
	/bin/gettext "Can not determine where start-diag is"
	echo ""
	exit 1
fi

unset TEST
TEST=thisTest

if [ -f "/var/opt/SUNWhwdiag/logs/hwdserver.pid" ]; then
	EDS_PID=`cat /var/opt/SUNWhwdiag/logs/hwdserver.pid`
	if [ ! ${TEST} = ${TEST}${EDS_PID} ] ; then
		# is this a process still active ?
		EDS_PID_A=`/bin/ps -efo pid | /usr/xpg4/bin/sed 's/ //g' | /usr/xpg4/bin/grep -F -x ${EDS_PID} `
		if [ ! ${TEST} = ${TEST}${EDS_PID_A} ] ; then
			l_KILL=`/bin/kill  ${EDS_PID} 2> /dev/null`
			sleep 3
			EDS_PID_A=`/bin/ps -efo pid | /usr/xpg4/bin/sed 's/ //g' | /usr/xpg4/bin/grep -F -x ${EDS_PID} `
			if [ ! ${TEST} = ${TEST}${EDS_PID_A} ] ; then
				 echo "Can not kill Hardware Diagnostic Suite Server. Please check permissions."
				 exit 1
			else
				/bin/gettext "Hardware Diagnostic Suite Server stopped."
				/bin/rm -f /var/opt/SUNWhwdiag/logs/hwdserver.pid
				/bin/rm -f /var/opt/SUNWhwdiag/logs/HWDServerRMIServer.log
				/bin/rm -f /tmp/HWDServerRMIServer.log
				/bin/rm -f /tmp/HandleMessage.log
				/bin/rm -f /tmp/javavtscmd.log
				/bin/rm -f /tmp/edserver1099
			fi

			echo ""
			exit 0;
		fi
 	fi
fi

## Try other avenues to stop HWDS Server
EDS_PID=`/bin/ps -ef | /bin/fgrep jre | /bin/fgrep "DHWDS" | /bin/fgrep -v fgrep | /bin/awk '{ print $2 }'`
if [ ! ${TEST} = ${TEST}${EDS_PID} ] ; then
		l_KILL=`/bin/kill ${EDS_PID}`
		/bin/gettext "Hardware Diagnostic Suite Server stopped."
		/bin/rm -f /var/opt/SUNWhwdiag/logs/hwdserver.pid
		/bin/rm -f /var/opt/SUNWhwdiag/logs/HWDServerRMIServer.log
		/bin/rm -f /tmp/HWDServerRMIServer.log
		/bin/rm -f /tmp/HandleMessage.log
		/bin/rm -f /tmp/javavtscmd.log
		/bin/rm -f /tmp/edserver1099
		echo ""
		exit 0

else 
	/bin/gettext  "Hardware Diagnostic Suite Server not found."
	echo ""
	exit 0
fi

