#!/bin/ksh

if [ -f /etc/opt/SUNWisp/ixsnagbls ]; then
        . /etc/opt/SUNWisp/ixsnagbls
else
# Second tier case where SUNWixtnm is not needed and the admin servers need    
# not run.     
        return 0
fi

if [ -f  /etc/opt/SUNWisp/globals ]; then
        . /etc/opt/SUNWisp/globals
else
# Second tier case where SUNWixtnm is not needed and the admin servers need
# not run.
        return 0
fi

StartNewsadServ ()
{
  ${NEWSADSERV_FILE} > /dev/null 2>&1 &
  NEWSADSERV_PID=$!
  sleep ${SLEEP_TIME}
  WritePidFile `GetChildPidFromParent ${NEWSADSERV_PID} ${NEWSADSERV_FILE}` ${NEWSADSERV_PID_FILE}
}

StopNewsadServ ()
{
  if [ -f ${NEWSADSERV_PID_FILE} ]; then
	NEWSADSERV_PID=`cat ${NEWSADSERV_PID_FILE}`
	${KILL} ${NEWSADSERV_PID} 2> /dev/null
  fi
}

Main ()
{
  if [ -f ${TNAMESERV_PID_FILE} ]; then
	pid=`cat ${TNAMESERV_PID_FILE}`
  fi
  if [ "${pid}X" != "X" ]; then
	  if [ "`CheckIfProcessAlive ${pid}`X" = "0X" ]; then
		StopNewsadServ
		CleanUp ${NEWSADSERV_PID_FILE}
		StartNewsadServ
	  else
		echo "${TNAMESERV_FILE} process not running or not healthy"
	  fi
  else
    	echo "${TNAMESERV_FILE} process not running"
  fi
}

Main $*

