#! /bin/bash
#=======================================================================
# NOTE: This one needs more work...
#-----------------------------------------------------------------------
scriptPath="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

javaClassName="sek.ase.auditor.AseAuditor"

##
## Stop the auditor
##
pidCount=$(ps -ef | grep "${javaClassName}" | grep -v grep | wc -l)
if [ ${pidCount} -gt 0 ]
then
	pidToKill=$(ps -ef | grep "${javaClassName}" | grep -v grep | awk '{printf "%s ", $2}')

	echo ""
	echo " * Stopping 'sek_ase_auditor' with PID=${pidToKill}"

	kill ${pidToKill}

	echo ""
	echo " * Waiting for 'sek_ase_auditor' with PID=${pidToKill} to end."
	echo ""
	while [ true ]
	do
		sleep 1

		pidToKill=$(ps -ef | grep "${javaClassName}" | grep -v grep | awk '{printf "%s ", $2}')
		pidCount=$(ps -ef | grep "${javaClassName}" | grep -v grep | wc -l)
		if [ ${pidCount} -eq 0 ]
		then
			break
		fi
		echo "   - Still Waiting for PID=${pidToKill} to end."
	done
	echo " * Stopped 'sek_ase_auditor' with PID=${pidToKill}"
	echo ""
else
	echo ""
	echo " * No 'sek_ase_auditor' is running."
	echo ""
fi
