#!/bin/sh
#
# Copyright (c) 2003-2007 eleven GmbH
# All rights reserved.
#
# chkconfig: 2345 40 30
# description: Starts and stops eXpurgate
#
# To install this startupscript:
# Copy this script to /etc/init.d/expurgate
# Copy the expurgate_sysconfig file to /etc/sysconfig/expurgate
# Edit the expurgate startup options in /etc/sysconfig/expurgate


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

# Source networking configuration.
. /etc/sysconfig/network

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

EXPURGATE_BIN=/usr/local/eleven/bin/expurgate

test -x $EXPURGATE_BIN || exit 5

EXPURGATE_SYSCONFIG=/etc/sysconfig/expurgate
test -r $EXPURGATE_SYSCONFIG || exit 6
. $EXPURGATE_SYSCONFIG

RETVAL=0

start() {
    echo -n "Starting mail service (expurgate)"
    daemon $EXPURGATE_BIN $EXPURGATE_OPTS -s
    RETVAL=$?
    echo 
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/expurgate
    return $RETVAL
}

stop() {
    echo -n "Shutting down mail service (expurgate)"
    killproc expurgate
    RETVAL=$?
    echo 
    [ $RETVAL -eq 0 ] && rm -rf /var/lock/subsys/expurgate
    return $RETVAL
}

case "$1" in
    start)
	start
        ;;

    stop)
	stop
        ;;

    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        stop
	sleep 3
        start
        ;;

    reload)
        echo -n "Reload mail service (expurgate)"
        ## Signal the daemon to reload its config. Most daemons
        ## do this on signal 1 (SIGHUP).
        killproc expurgate -HUP
        RETVAL=$?
        echo
        ;;

    status)
        echo -n "Checking for service expurgate: "
        status expurgate
	RETVAL=$?
        ;;

    *)
        echo "Usage: $0 {start|stop|status|restart|reload}"
        RETVAL=1
        ;;
esac
exit $RETVAL
