Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:20:57

0001 #!/usr/bin/bash
0002 # start the background monitoring and check if it is still
0003 # alive
0004 # can be started from a cronjob (checks every 5 minutes) by 
0005 # */5 * * * * /export/software/oncs/OnlMon/install/bin/monserver.sh >& /dev/null
0006 [ -f ~/.bash_profile ] && . ~/.bash_profile
0007 
0008 if [ $# -le 1 ]
0009 then
0010     echo "Usage : $0 {start|status|stop|restart|valgrind} n (1-5)"
0011     exit 1
0012 fi
0013 hostname=`hostname -s`
0014 piddir=/tmp/sphnxonlmon
0015 pidfile=${piddir}/onlmon$2
0016 #echo $hostname
0017 [ -d $piddir ] || mkdir $piddir
0018 [ -f $pidfile ] && touch $pidfile
0019 
0020 [ -d /scratch/phnxrc/onlmon ] || mkdir -p /scratch/phnxrc/onlmon
0021 
0022 case "$1" in
0023     status)
0024         if [ -s $pidfile ]
0025         then
0026             ps `cat $pidfile`
0027             if [ $? != 0 ]
0028             then
0029                 echo "Monitoring Dead"
0030                 rm $pidfile
0031                 exit 1
0032             else
0033                 #echo "Monitoring running"
0034                 exit 0
0035             fi
0036         else
0037             echo "Monitoring not running"
0038             [ -f $pidfile ] && rm $pidfile
0039             exit 1
0040         fi
0041         ;;
0042     start)
0043         $0 stop $2
0044         #echo starting
0045         #echo $hostname.$2.cmd
0046     if [[ "$(hostname)" =~ ^'mvtx'[0-5] ]]
0047     then
0048         d=`date +%Y%m%d`
0049         t=`date +%H%M`
0050         nohup root.exe -l $ONLMON_SERVERWATCHER/$hostname.monitorserver.$2.cmd > /scratch/phnxrc/onlmon/${hostname}.monitorserver.$2.log 2> /scratch/phnxrc/onlmon/${hostname}.monitorserver.$2_${d}_${t}.err &
0051     else
0052         nohup root.exe -l $ONLMON_SERVERWATCHER/$hostname.monitorserver.$2.cmd >& /scratch/phnxrc/onlmon/${hostname}.monitorserver.$2.log &
0053     fi
0054     #nohup root.exe -l $ONLMON_SERVERWATCHER/$hostname.monitorserver.$2.cmd >& /scratch/phnxrc/onlmon/${hostname}.monitorserver.$2.log &
0055         pid=`echo $!`
0056         echo $pid > $pidfile
0057         ;;
0058     stop)
0059         if [ -s $pidfile ]
0060         then
0061             kill -INT `cat $pidfile`
0062             if [ $? != 0 ]
0063             then
0064                 echo "No Online Monitoring process " `cat $pidfile`
0065             else
0066                 echo "Sending INT signal to Online Monitoring process " `cat $pidfile`
0067                 sleep 1
0068                 counter=0
0069                 while ps -p `cat $pidfile` > /dev/null
0070                 do
0071                     sleep 1
0072                     counter=$[$counter + 1]
0073                     if [ $counter -gt 5 ]
0074                     then
0075                         echo "Online Monitoring process " `cat $pidfile` " survived SIGINT signal, sending SIGKILL"
0076                         kill -9 `cat $pidfile`
0077                     fi
0078                 done
0079             fi
0080             rm $pidfile
0081         fi
0082         ;;
0083     restart)
0084         $0 start $2
0085         ;;
0086 esac
0087 
0088 #[[ -d /scratch/phnxrc/onlmon ]] || mkdir -p /scratch/phnxrc/onlmon
0089 #[[ -d /tmp/sphnxonlmon ]] || mkdir /tmp/sphnxonlmon