#!/bin/sh

MAILGRAPH_CONFIG=/etc/default/mailgraph
NAME=mailgraph
DAEMON=/usr/sbin/mailgraph.pl
PID_FILE=/var/run/mailgraph.pid
RRD_DIR=/var/cache/mailgraph

if [ -f $MAILGRAPH_CONFIG ]; then
  . $MAILGRAPH_CONFIG
else
  exit 0
fi  

test -x /usr/sbin/mailgraph.pl || exit 0

case "$1" in
  start)
    echo -n "Starting Postfix Mail Statistics: $NAME"
    start-stop-daemon -S -q -b -p $PID_FILE -x $DAEMON -- -l $MAIL_LOG -d --daemon_rrd=$RRD_DIR
    echo "."
    ;;
  stop)
    echo -n "Stopping Postfix Mail Statistics: $NAME"
    if [ -f $PID_FILE ]; then
      kill `cat $PID_FILE`
      rm $PID_FILE
    fi
    echo "."
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  force-reload)
    $0 restart
    ;;
  *)
    echo "Usage: $0 start|stop|restart|force-reload"
    exit 1
    ;;
esac
