#! /bin/sh
#
# munin-node	Control the Munin Node Server (formerly Linpro RRD client)
#
# chkconfig: 2345 90 10
# description: munin node agents
# processname: munin-node
# config: /etc/munin/munin-node.conf
# pidfile: /var/run/muin-node.pid

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

RETVAL=0
PROCNAME=munin-node

PIDFILE=/var/run/munin/munin-node.pid
LOCKFILE=/var/lock/subsys/munin-node
MUNINUSER=munin

### FIXME PLEASE!!!!!!!
PERL=/usr/bin/perl5.8.8

mkdir -p /var/run/munin 2>/dev/null
chown munin /var/run/munin

# See how we were called.
case "$1" in
  start)
        msg_starting "Munin Node"
        start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$MUNINUSER" -- /bin/su -s /bin/bash -c $PROCNAME  "$MUNINUSER"
        RETVAL=$?
    ;;
  stop)
		msg_stopping "Munin Node"
		stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$MUNINUSER" -- $PERL
		RETVAL=$?
    ;;
  status)
	status --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$MUNINUSER"  -- $PERL
	RETVAL=$?
    ;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
    ;;
  *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
esac

exit $RETVAL
