sercheck 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/sh
  2. #
  3. # $Id$
  4. #
  5. # use to check whether all ser processes are running; if not, restart
  6. # and issue an alert; run from cron daemon for best results :-)
  7. #
  8. [email protected]
  9. SERHOME=/home/srouter
  10. export SERDIR=$SERHOME/sip_router
  11. BIN=$SERDIR/ser
  12. COREDIR=$SERHOME/core
  13. CORE=$COREDIR/core
  14. ETC=/etc/sr.cfg
  15. PROCCNT=`ps -C sr --no-headers -o pid | wc -l`
  16. CH=`grep "^children" $ETC | awk -F= ' { print $2 } '`
  17. ALL=`expr $CH + 1`
  18. TMP=/tmp/seralert.$$
  19. if [ $PROCCNT -ne $ALL ] ; then
  20. # try again first -- it might have been a temporary
  21. # failure during 'sr restart'
  22. # two seconds longer failure is not too bad...UAs will
  23. # just retransmit and user are used to longer call
  24. # set-up times from GSM...
  25. sleep 2
  26. PROCCNT=`ps -C sr --no-headers -o pid | wc -l`
  27. fi
  28. if [ $PROCCNT -ne $ALL ] ; then
  29. cd $SERDIR
  30. echo "Alarm: ser restart occurred on `date` at $HOSTNAME" > $TMP
  31. if [ -r $BIN -a -r $CORE ] ; then
  32. echo "----------------------------------" >> $TMP
  33. DATE=`date "+%Y-%m-%d--%H-%M"`
  34. NEWCORE=$COREDIR/core.$DATE
  35. mv $CORE $NEWCORE
  36. echo core stored in $NEWCORE >> $TMP
  37. gdb $BIN $NEWCORE -x test/bt.gdb -batch >> $TMP
  38. chmod a+r $NEWCORE
  39. ( cd $SERDIR; tar cf - . ) | gzip > $COREDIR/ser.$DATE.tgz
  40. else
  41. echo "no core found" >> $TMP
  42. fi
  43. /etc/init.d/sr restart
  44. mail -s "ser restart occurred" $NOTIFY < $TMP
  45. rm -f $TMP
  46. fi