#!/bin/sh
#
# munin-asyncd	Start/Stop the munin-asyncd daemon.
#
# chkconfig:	2345 91 09
# description:	munin-asyncd enables asyncronous fetching of
#		metrics from munin-node in a Munin monitoring setup.
#
# processname:	munin-asyncd
# pidfile:	/var/run/munin-asyncd.pid
#
### BEGIN INIT INFO
# Provides:		munin-asyncd
# Required-Start:	$local_fs $remote_fs $network
# Required-Stop:	$local_fs $remote_fs $network
# Default-Start:	2 3 4 5
# Default-Stop:		0 1 6
# Short-Description:	Starts and stops munin-asyncd
# Description:		munin-asyncd enables asyncronous fetching of
#			metrics from munin-node in a Munin monitoring setup.
### END INIT INFO

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

start() {
	# Check if the service is already running?
	if [ -f /var/lock/subsys/munin-asyncd ]; then
		msg_already_running "munin-asyncd"
		return
	fi

	msg_starting "munin-asyncd"
	daemon /usr/sbin/munin-asyncd
	RETVAL=$?
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/munin-asyncd
}

stop() {
	if [ ! -f /var/lock/subsys/munin-asyncd ]; then
		msg_not_running "munin-asyncd"
		return
	fi

	msg_stopping "munin-asyncd"
	killproc munin-asyncd
	rm -f /var/lock/subsys/munin-asyncd
}

condrestart() {
	if [ ! -f /var/lock/subsys/munin-asyncd ]; then
		msg_not_running "munin-asyncd"
		RETVAL=$1
		return
	fi

	stop
	start
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload|force-reload)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  status)
	status --pidfile /var/run/munin-asyncd.pid munin-asyncd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
