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


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

# Get network config
. /etc/sysconfig/network

# Check that networkin 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
	;;
  restart|force-reload)
	$0 stop
	$0 start
	exit $?
	;;
  status)
	status shaperd
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
