#! /bin/sh
### BEGIN INIT INFO
# Provides:          mrtg
# Required-Start:    
# Required-Stop:     
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mrtg init script
# Description:       This file is used to start, stop, restart, 
#                                        and determined status of the mrtg
# daemon.
# Author:                        iceflatline <iceflatline@gmail.com>
### END INIT INFO

### START OF SCRIPT
set -e
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="mrtg"
NAME=mrtg
DAEMON=/usr/bin/$NAME
PIDFILE=/etc/${NAME}/$NAME.pid
CONFFILE=/etc/${NAME}/$NAME.cfg
DAEMON_ARGS="--daemon --pid-file=$PIDFILE $CONFFILE"
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the mrtg package is not installed
[ -x "$DAEMON" ] || exit 0

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

# Function that starts the mrtg daemon
start()
{
        env LANG=C start-stop-daemon --start --quiet \
        --exec $DAEMON -- $DAEMON_ARGS
}

# Function that stops the mrtg daemon
stop()
{
        start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 \
        --pidfile $PIDFILE 
}

case "$1" in
  start)
        log_daemon_msg "Starting $DESC" 
        start
        case "$?" in
                0) log_end_msg 0 ;;
                1) log_end_msg 1 ;;
        esac
        ;;
  stop)
        log_daemon_msg "Stopping $DESC"
        stop
        case "$?" in
                0) log_end_msg 0 ;;
                1) log_end_msg 1 ;;
        esac
        ;;
  restart|force-reload)
        log_daemon_msg "Restarting $DESC" 
        stop
        case "$?" in
          0|1)
                start
                case "$?" in
                        0) log_end_msg 0 ;;
                        1) log_end_msg 1 ;; 
                esac
                ;;
        esac
        ;;
        status)
    status_of_proc "$DAEMON" "$NAME"  
    ;;
  *)
        echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" 
        ;;
esac
exit 0
### END OF SCRIPT
