#!/bin/sh
#
# policyd-weight	policyd-weight is a policy daemon for postfix
#
# chkconfig: - 75 25
# description:	A policy daemon for postfix, allows you to score DNSBLs, 
#		HELO, MAIL FROM, Client IP Addresses before queuing
# processname: policyd-weight
# config: /etc/policyd-weight.conf
# pidfile: /var/run/policyd-weight/policyd-weight.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

RUNAS=_policyd_weight

PIDFILE=/var/run/policyd-weight/policyd-weight.pid
LOCKFILE=/var/lock/subsys/policyd-weight
RETVAL=0

SourceIfNotEmpty /etc/sysconfig/policyd-weight

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root \
	-- policyd-weight start
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$RUNAS" \
	--displayname policyd-weight -- perl
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading policyd-weight
	stop_daemon --pidfile "$PIDFILE" --expect-user "$RUNAS" -HUP \
	--displayname policyd-weight -- perl
	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" --displayname policyd-weight -- perl
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
