#!/bin/sh
#
#  /etc/convers/check.sh by Darryl Miles - G7LED 09/03/1994
#
#  Rather simple script to test that conversd is still running should it
#  ever crash (of course it wont!!!).  This can be setup to run as 'root'
#  from 'crond' say every 10 minutes with.
#
#  Add into root's crontab file:
#
#  0,10,20,30,40,50 * * * * /etc/convers/check.sh
#
#  If you have vixie cron you can get away with:
#
#  */10 * * * * /etc/convers/check.sh
#
#
#  You'll need, pidof, logger, kill, touch, find.
#
#  pidof.c was obtained from the init package, as its recommended you get
#  this package for the complete information on the util command 'pidof'.
#  You can compile with 'gcc pidof.c -s -o pidof' and move the executable
#  into /usr/bin/ so that it maybe found when this script is run.
#
#  logger is a util which comes with the syslog package(s), if you do not
#  use or have syslog, then just hash this line out.
#
#  This script may also be used at bootup to kick xconversd into play.
#

# 'xconversd' or 'conversd' whichever you run.

#pid=`pidof conversd 2>/dev/null`
pid=`pidof xconversd 2>/dev/null`
MailLock=/etc/convers/MAILLOCK

if kill -0 $pid 2>/dev/null
then
   true
#   logger -plocal6.emerg -t'check.sh' "Conversd up and running"
else
   logger -plocal6.emerg -t'check.sh' "Conversd was found not to be running - restarted"
# 'xconversd' or 'conversd' whichever you run.
#   /etc/conversd -s3 &
    /etc/xconversd -s3 &
   if [ ! -f $MailLock ] || [ -n "`find $MailLock -mmin +1440 -print 2>/dev/null`" ]
   then
      (
      cat <<!EOF!
Subject: Conversd restart

Conversd has been restarted because it was not found to be running when this
script '$0' was run (probably from crond).

This is the FIRST occurence of this possible problem in the last 24 hours.
!EOF!
      ) | mail root

      touch $MailLock
   fi
fi
