#!/bin/bash
#
# IPCop rc script for munin-node
#
#
# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
#
# Copyright (C) 2007 Olaf (weizen_42) Westrik
#
# $Id: rc.munin-node 216 2007-07-28 21:07:33Z weizen_42 $
# 

BIN="/usr/sbin/munin-node"

# start options for daemon
OPTIONS="--config /var/ipcop/munin/munin-node.conf"


DESCRIPTION="Munin node"


# find out if daemon is running
PID=`ps -A|/bin/grep munin|/bin/grep -v "rc.munin"|/usr/bin/awk '{print $1}'`


stop()
{
  echo "Stopping $DESCRIPTION"
  /bin/kill $PID
}

start()
{
  echo "Starting $DESCRIPTION"
  $BIN $OPTIONS
}

case $1 in
  start)
    if [ "$PID" != "" ]; then
      echo "$DESCRIPTION is already running"
      exit 1
    fi
    start
    ;;

  stop)
    if [ "$PID" == "" ]; then
      echo "$DESCRIPTION is not running"
      exit 1
    fi
    stop
    ;;

  restart)
    if [ "$PID" != "" ]; then
      stop
    fi
    start
    ;;

  status)
    if [ "$PID" == "" ]; then
      echo "$DESCRIPTION is not running"
    else
      echo "$DESCRIPTION is running (PID $PID)"
    fi
    ;;

  *)
    echo "Usage: $0 {start|stop|restart|status}"
    ;;
esac

