#!/bin/bash
#
# chkconfig: - 75 25
# description: Postfix Policy Daemon
# processname: httpd
# config: /etc/policyd/cluebringer.conf
# pidfile: /var/run/cbpolicyd.pid
# processname: cbpolicyd
### BEGIN INIT INFO
# Provides:          policyd
# Required-Start:    $remote_fs 
# Should-Start: $time ypbind sendmail
# Required-Stop:     $syslog $remote_fs
# Should-Stop: $time ypbind sendmail
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: policyd anti spam solution
# Description:       Start policyd for greylisting
### END INIT INFO

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
POLICYD_BIN=/usr/sbin/cbpolicyd
test -x $POLICYD_BIN || { echo "$POLICYD_BIN not installed";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Check for existence of needed config file and read it
POLICYD_CONFIG=/etc/policyd/cluebringer.conf
test -r $POLICYD_CONFIG || { echo "$POLICYD_CONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }


. /etc/rc.status

# Reset status of this service
rc_reset

start() {
	echo -n $"Starting cbpolicyd: "
        startproc $POLICYD_BIN --config $POLICYD_CONFIG

        # Remember status and be verbose
        rc_status -v
}


stop() {
	echo -n $"Shutting down cbpolicyd: "
	killproc -TERM cbpolicyd

        # Remember status and be verbose
        rc_status -v

}

restart() {
	stop
	start
}	


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

exit $RETVAL
