#!/bin/sh
#
# mrtgd		A Debian init script for launching MRTG.
#		Place in /etc/init.d/
#
# Author:	George Borisov <i93.borg@gmail.com>
#
# Version	@(#)mrtgd  1.0  30-Jun-2005  <i93.borg@gmail.com>

set -e

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Multi Router Traffic Grapher Daemon"
NAME="mrtg"
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/mrtgd
CFG="/etc/mrtg/mrtg.cfg"

test -x $DAEMON || exit 0

if [ ! -e $CFG ]; then 
  echo "ERROR: $CFG not found"
  exit 0
fi

d_start() {
        $DAEMON --pid-file=$PIDFILE $CFG
}

d_stop() {
        start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                --name $NAME
}

d_reload() {
        start-stop-daemon --stop --quiet --pidfile $PIDFILE \
                --name $NAME --signal 1
}

case "$1" in
  start)
        echo "Starting $DESC: $NAME"
        d_start
        echo "."
        ;;
  stop)
        echo "Stopping $DESC: $NAME"
        d_stop
        echo "."
        ;;
  #reload)
        #	FIXME: Can MRTG be reloaded with -HUP?
	#	If so, uncomment here and in the usage
	#	instructions below.
        #
        # echo -n "Reloading $DESC configuration..."
        # d_reload
        # echo "done."
  #;;
  restart|force-reload)
        #
        #       If the "reload" option is implemented, move the "force-reload"
        #       option to the "reload" entry above. If not, "force-reload" is
        #       just the same as "restart".
        #
        echo "Restarting $DESC: $NAME"
        d_stop
        sleep 1
        d_start
        echo "."
        ;;
  *)
        # echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
        exit 1
        ;;
esac

exit 0
