#!/bin/tcsh
#
# description: check that epics2rrd (EPICS->RRD update) script is running
#
# processname: checkup-epics2rrd

########### SVN repository information ###################
# $Date: 2010-08-26 21:07:09 +0000 (Thu, 26 Aug 2010) $
# $Author: jemian $
# $Revision: 208 $
# $HeadURL$
# $Id: checkup-epics2rrd.csh 208 2010-08-26 21:07:09Z jemian $
########### SVN repository information ###################

setenv RRD_LOGS_BASE_DIR /home/joule/WEB33/www/rrd
setenv SCRIPT  ${RRD_LOGS_BASE_DIR}/epics2rrd.csh
setenv LOGFILE ${RRD_LOGS_BASE_DIR}/epics2rrd.log
setenv PIDFILE ${RRD_LOGS_BASE_DIR}/epics2rrd.pid

#echo "#====================" 	 >>& ${LOGFILE}
#echo "#`date`" 	 >>& ${LOGFILE}
set pid = `/bin/cat ${PIDFILE}`
#set test = `/bin/ps -p ${pid} --no-header -o pid`
set test = `/bin/ps -p ${pid} -o pid | sed 's+PID++'`

##/bin/echo "`env`"	 >>& ${LOGFILE}
#/bin/echo "pid = <$pid>"	 >>& ${LOGFILE}
#/bin/echo "test = <$test>"	 >>& ${LOGFILE}

if (${pid} != ${test}) then
  echo "#====================" 	 >>& ${LOGFILE}
  echo "# `/bin/date` could not identify running process ${pid}, restarting" >>& ${LOGFILE}
  #echo `${SCRIPT} stop` >& /dev/null
  #echo `${SCRIPT} start` >& /dev/null
  
  echo `${SCRIPT} stop`  >>& ${LOGFILE}
  echo `${SCRIPT} start` >>& ${LOGFILE}
#else
#  echo "${pid} and ${test} must be equal" >>& ${LOGFILE}
endif

#echo "end of checkup script"  >>& ${LOGFILE}
#  log EPICS PVs into RRD for WWW browsing of logs
#  * * * * * /home/joule/WEB33/www/rrd/htmlCreate.py >& /home/joule/WEB33/www/rrd/htmlCreate.log
#  1,6,11,16,21,26,31,36,41,46,51,56 * * * * /home/joule/WEB33/www/rrd/checkup-epics2rrd.csh 2>&1 /dev/null
