#!/bin/sh
#
# postgrey	This script starts and stops the postgrey daemon.
#
# chkconfig: - 75 25
# description: Postfix Greylisting Policy Server	
# processname: postgrey
# pidfile: /var/run/postgrey/postgrey.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

RUNAS=postgrey
PIDFILE=/var/run/postgrey/postgrey.pid
LOCKFILE=/var/lock/subsys/postgrey
SourceIfNotEmpty /etc/sysconfig/postgrey
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$RUNAS" -- \
	postgrey -d --user="$RUNAS" --group="$RUNAS" --pidfile=$PIDFILE $POSTGREY_OPTIONS \
	--greylist-text=\"$GREYLIST_TEXT\"
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$RUNAS" --name postgrey -- \
	postgrey
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading postgrey
	stop_daemon --pidfile "$PIDFILE" --expect-user "$RUNAS" -HUP --name postgrey -- postgrey
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user "$RUNAS" --name postgrey -- postgrey
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
