#!/bin/sh
#
# $Id: scud.sh.sample,v 1.6 2003/07/10 01:19:02 drq Exp $
#
# chkconfig: 2345 50 50
# description: Selective Callerid and Unavailable Deterant

binary=/usr/local/sbin/scud
pidfile=/var/run/scud.pid

#
# function for starting scud
#
startscud() (
   if [ -x $binary ]; then
      $binary &
   fi
   return 0;
)

#
# function for stopping scud
#
stopscud() (
   if [ -f $pidfile ]; then
      kill -9 `cat $pidfile`
      rm -f $pidfile
   fi
)

case "$1" in
   reload)
      echo reload not supported
      ;;

   restart)
      stopscud
      startscud
      echo -n ' scud'
      ;;

   start)
      startscud
      echo -n ' scud'
      ;;

   stop)
      stopscud
      echo -n ' scud'
      ;;

   status)
      # see if scud is running and report pid
      if [ -f $pidfile ]; then
         pid=`cat $pidfile`
         if ps -p $pid >/dev/null 2>&1; then
            echo scud is running \(pid: $pid\)
         else
            echo scud is stopped
         fi 
      else
         echo scud is stopped
      fi
      ;;

    *)
       echo "Usage: `basename $0` {start|stop|status}" >&2
       exit 64
       ;;
esac
exit 0
