#!/bin/sh
#
# chkconfig: - 33 67
# description: swatch was originally written to actively monitor
#      messages asthey are written to a log file via the UNIX syslog utility.  
#
#

if [ ! -f /etc/swatch.conf ]; then
   exit 0
fi

case "$1" in
  start)
      if [ ! -f /var/lock/subsys/swatch ] ; then
         echo -n "Starting SWATCH: "
         swatch -c /etc/swatch.conf  -t /var/log/messages --daemon &
         echo
         touch /var/lock/subsys/swatch
      else
         echo "swatch has already been driven"
      fi
      ;;
  stop)
      echo -n "Shutting down SWATCH: "
      for i in `ps ax|grep 'swatch'| grep perl | awk '{print $1}'`
      do
	kill -KILL $i
      done
      rm /var/lock/subsys/swatch
      ;;
  restart)
      $0 stop
      $0 start
      ;;
  *)
      echo "Usage: swatch.init {start|stop|restart}"
      exit 1
esac

exit 0
