#!/bin/sh
#
# shaperd	This script is used to start and stop shaperd service
#
# chkconfig:	345 83 17
#
# description:	Shaperd is a deamon to divide bandwitdh between LAN \
#		clients.
#
# Author:	Adam Piatyszek "ediap" <ediap@et.put.poznan.pl>


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

# Get network config
. /etc/sysconfig/network

# Configuration file
[ -f /etc/sysconfig/shaperd ] && . /etc/sysconfig/shaperd

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

RETVAL=0
# See how we were called.
case "$1" in
  start)
	# Check if the service is already running
	if [ ! -f /var/lock/subsys/shaperd ]; then
		msg_starting Shaperd
		daemon /usr/sbin/shaperd
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/shaperd
	else
		msg_already_running Shaperd
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/shaperd ]; then
		# Stop daemon
		msg_stopping Shaperd
		killproc shaperd
		rm -f /var/lock/subsys/shaperd >/dev/null 2>&1
	else
		msg_not_running Shaperd
	fi
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/shaperd ]; then
	    msg_reloading Shaperd
	    killproc shaperd -HUP
	    RETVAL=$?
	else
	    msg_not_running shaperd
	fi
	;;
  restart)
	$0 stop
	# Does shaperd need a break?
	if [ -n "$SHAPERD_DELAY" ]; then
		echo "Waiting $SHAPERD_DELAY seconds..."
		sleep $SHAPERD_DELAY
	fi
	$0 start
	exit $?
	;;
  status)
	status shaperd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
