#! /bin/sh
#
# smokeping:	Controls the smokeping daemon.
#
# chkconfig:	345 70 30
# description:	latency logging and graphing system
# processname:	smokeping

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

# Get network 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 smokeping
		exit 1
	fi
else
	exit 0
fi

checkconfig() {
	/usr/bin/smokeping --check || exit 1
}

start() {
	if [ ! -f /var/lock/subsys/smokeping ]; then
		msg_starting smokeping
		daemon --pidfile /var/run/smokeping/smokeping.pid --user smokeping /usr/bin/smokeping
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/smokeping
	else
		msg_already_running smokeping
	fi
}

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

RETVAL=0
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart|reload)
	checkconfig
	stop
	start
	exit $?
	;;
  status)
	status smokeping
	checkconfig
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|status}"
	exit 3
esac

exit $RETVAL
