
# Filename: S89rdsd
# 
# Description:
#
# 	Start Diagnostic daemon.
#
#        INTEL CORPORATION PROPRIETARY INFORMATION		  
#								 
#  This software is supplied under the terms of a license	
#  agreement or nondisclosure agreement with Intel Corporation
#  and may not be copied or disclosed except in accordance
#  with the terms of that agreement.			
#
# Note on Filename:
#	It is important that the name of this script be such that
#	it is alphabetically after the name of the NFS script.
#	This gurantees that this script is started after NFS
#	since the diagnostic daemon needs NFS support. 
#
# Modification History:
# $Log: S89rdsd,v $
# Revision 1.3  1993/03/25  18:57:02  mouli
# Took off debug echo
#
# Revision 1.2  1993/03/25  18:16:49  mouli
# 1. Took care of killing dtx_serv when the daemon is stopped.
# 2. dsd should be invoked from the directory where the diagnostic s/w
#    resides so that the daemon knows about the location of dtx_serv.
#
# Revision 1.1  1993/03/25  00:31:34  mouli
# Initial revision
#
#
USAGE="Usage: $0 {start | stop }"
# Set up process names
# The dsd_path is important for starting up diagnostic daemon
# for it to know whereabouts of dtx_serv. Any change to the
# diagnostic s/w directory structure should reflect here.
dsd_path=/u/paragon/diag
dsd_proc=dsd
dtx_proc=dtx_serv
dsd_exe=${dsd_path}/${dsd_proc}
PROCS="${dsd_proc} ${dtx_proc}"
stat=0
# PATH is set here and exported so that the daemon and its executed
# programs get a known environment.
# 
PATH=".:/bin:/usr/bin:/etc:/usr/lib:/usr/dbin:/usr/ldbin:${dsd_path}"
export PATH

if [ -x /bin/ps ] ; then
    /bin/ps 2> /tmp/ps.err$$ 1>&2
    if grep "not booted" /tmp/ps.err$$ ; then
	PS="/bin/ps -n /unix.old"
    else
        PS="/bin/ps"
    fi
    rm -f /tmp/ps.err$$
else
    echo "$0: Can't find ps"
    exit 1
fi
case $1 in
	'start')
		/bin/su root -c "$PS -e"  2>/dev/null | \
			/usr/bin/fgrep ${dsd_proc} > /dev/null 2>&1

		if [ $? -eq 0 ]
		then
			echo "DSD is already running.  DSD start aborted."
			exit 0
		fi
	
		if [ ! -f ${dsd_exe} ] ; then
			echo "$0: Diagnostic daemon ${dsd_exe} is missing!"
			stat=1
		elif [ ! -x ${dsd_exe} ] ; then
			echo "$0: Diagnostic daemon ${dsd_exe} is not executable!"
			stat=1
		fi
		if [ ${stat} -eq 0 ] ; then
			(cd ${dsd_path}; ${dsd_exe})
			echo "DSD started"
		else
			echo "DSD could not be started !"
		fi
		exit ${stat}
		;;
	'stop')

		echo "DSD shutdown: \c"

#
# Get our ps out of the way
#
		/bin/su root -c "$PS -e"  2>/dev/null 1>/tmp/ps$$

#
# Now, kill the procs
#
# There is a hole here because some procs
# may die without us knowing about them
# because we are working from an old image.
#
		PIDS=`(
			for proc in ${PROCS}
			do
				cat /tmp/ps$$ | /bin/grep $proc | \
				/bin/grep -v grep | /usr/bin/awk '{ print $1 }'
			done )`

		if [ "${PIDS}" != "" ]
		then
			/bin/kill ${PIDS} 2> /dev/null
			sleep 5
			echo "[DSD Shutdown Complete]"
		else
			echo "DSD is not running currently"
		fi

		rm -f /tmp/ps$$
		;;
	*)
		echo $USAGE
		exit 1
		;;
esac
