#!/bin/sh
#
# chkconfig: 345 82 28
# description: The pop-before-smtp daemon watches the mail log for \
#              successful mailbox accesses, and adds the source IP \
#              addresses to a file Postfix uses to allow relaying \
#              for a fixed amount of time.
#
# processname: pop-before-smtp
# pidfile: /var/run/pop-before-smtp.pid
#

# Sanity checks.
[ -x /usr/sbin/pop-before-smtp ] || exit 0

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

# Default values
POP_BEFORE_SMTP="pop-before-smtp"
POP_BEFORE_SMTP_OPTIONS="--daemon=/var/run/pop-before-smtp.pid"

# Source config file
[ -f /etc/sysconfig/pop-before-smtp ] && . /etc/sysconfig/pop-before-smtp

RETVAL=0

start() {
    echo -n $"Starting pop-before-smtp daemon: "
    daemon $POP_BEFORE_SMTP $POP_BEFORE_SMTP_OPTIONS
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$POP_BEFORE_SMTP
}

stop() {
    echo -n $"Stopping pop-before-smtp daemon: "

    killproc $POP_BEFORE_SMTP
    RETVAL=$?
    echo
    if [ $RETVAL -eq 0 ]; then
        rm -f /var/lock/subsys/$POP_BEFORE_SMTP
        rm -f /var/run/pop-before-smtp.pid
    fi
}

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