#!/bin/sh
#
# chkconfig:	345 60 20
# description:	The rstat protocol allows users on a network to retrieve \
#		performance metrics for any machine on that network.
# processname:	rpc.rstatd

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

# Get config.
. /etc/sysconfig/network

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down rstatd
		exit 1
	fi
else
	exit 0
fi

# Get rstatd config
[ -f /etc/sysconfig/rstatd ] && . /etc/sysconfig/rstatd

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/rstatd ]; then
		msg_starting rstatd
		daemon rpc.rstatd
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/rstatd
	else
		msg_already_running rstat
	fi
}

stop() {
	if [ -f /var/lock/subsys/rstatd ]; then
		msg_stopping rpc.rstatd
		killproc rpc.rstatd
		rm -f /var/lock/subsys/rstatd >/dev/null 2>&1
	else
		msg_not_running rstatd
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  status)
	status rpc.rstatd
	exit $?
	;;
  restart|force-reload)
	stop
	start
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
