#!/bin/bash
#
# Startup script for the mailgraph service
#
# chkconfig: - 82 28
# description: mailgraph mail log file analyzer
# processname: mailgraph
# pidfile: /var/run/mailgraph.pid
# config: 

MAILLOG=/var/log/maillog
PRIORITY=-19

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

if [ -f /etc/sysconfig/mailgraph ]; then
        . /etc/sysconfig/mailgraph
fi

# Path to the mailgraph script.
exe=/usr/sbin/mailgraph
prog=mailgraph
RETVAL=0

start() {
    echo -n $"Starting $prog: "
    daemon nice $PRIORITY $exe -l $MAILLOG -d \
        --daemon-pid=/var/run/mailgraph.pid   \
        --daemon-rrd=/var/lib/mailgraph $OPTIONS

    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    killproc $exe
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog /var/run/$prog.pid
}
reload() {
    echo -n $"Reloading $prog: "
    killproc $exe -HUP
    RETVAL=$?
    echo
}

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

exit $RETVAL
