#! /bin/sh
#
# qmail        This starts and stops qmail.
#
# chkconfig: 2345 80 30
# description:  qmail is a small, fast, secure replacement \
#               for the sendmail package, which is the \
#               program that actually receives, routes, \
#               and delivers electronic mail. \
#
# config: /etc/sysconfig/network

PATH=/sbin:/bin:/usr/bin:/usr/sbin

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

# Get config.
test -f /etc/sysconfig/network && . /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "yes" ] || exit 0

[ -f /var/qmail/bin/qmail-send ] || exit 1

RETVAL=0

start(){
    echo -n "Starting qmail: "
    exec env - PATH="/var/qmail/bin:$PATH" \
        qmail-start "`cat /etc/dot-qmail`" splogger qmail &
    RETVAL=$?
    echo
    touch /var/lock/subsys/qmail
    return $RETVAL
}

stop(){
    echo -n "Stopping qmail: "
    killproc qmail-send
    RETVAL=$?
    echo
    rm -f /var/lock/subsys/qmail
    return $RETVAL

}

restart(){
    stop
    start
}

# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status qmail-send
        ;;
    restart)
        restart
        ;;
    reload)
        reload
        ;;
    *)
        echo "Usage: qmail {start|stop|status|restart|reload}"
        RETVAL=1
esac

exit $RETVAL
