#!/bin/sh

# process checker

# To check for your process every 10 minutes, put the following line in your
# crontab:
#    0,10,20,30,40,50 * * * *   /path/to/binchk
# And if you don't want to get email from crontab when it checks your process,
# put the following in your crontab:
#    0,10,20,30,40,50 * * * *   /path/to/binchk >/dev/null 2>&1
#

# change this to the directory you run your bin from:
home="/usr/local/silc"

# binary executable
bin="silcd"

########## you probably don't need to change anything below here ##########

cd $home

# touch a tmp file so we know it's working:
touch logs/.silcd_monitored

if test -r var/$bin.pid; then
  # there is a pid file -- is it current?
  binpid=`cat var/$bin.pid`
  if `kill -CHLD $binpid >/dev/null 2>&1`; then
    # it's still going
    # back out quietly
    exit 0
  fi
  echo ""
  echo "Stale $bin.pid file (erasing it)"
  rm -f $bin.pid
fi
echo
echo "Couldn't find silcd running.  Reloading it..."
echo
$home/sbin/$bin
exit 0
