#!/bin/bash
#
# pysrs	This shell script takes care of starting and stopping pysrs.
#
# chkconfig: 2345 80 30
# description: Milter is a process that filters messages sent through sendmail.
# processname: pysrs
# config: /etc/mail/pysrs.cfg
# pidfile: /var/run/milter/pysrs.pid

python="python2.4"

pidof() {
	set - ""
	if set - `ps -e -o pid,cmd | grep "${python} pysrs.py"` &&
	  [ "$2" != "grep" ]; then
	  echo $1
	  return 0
	fi
	return 1
}

# Source function library.
. /etc/rc.d/init.d/functions

[ -x /var/log/milter/pysrs.sh ] || exit 0

RETVAL=0
prog="pysrs"

start() {
	# Start daemons.

	echo -n "Starting $prog: "
	daemon --check pysrs --user mail /var/log/milter/pysrs.sh
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/pysrs
	return $RETVAL
}

stop() {
	# Stop daemons.
	echo -n "Shutting down $prog: "
	killproc pysrs
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/pysrs
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	stop
	start
	RETVAL=$?
	;;
  condrestart)
	if [ -f /var/lock/subsys/pysrs ]; then
	    stop
	    start
	    RETVAL=$?
	fi
	;;
  status)
	status pysrs
	RETVAL=$?
	;;
  *)
	echo "Usage: $0 {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL
