#! /bin/sh
# /etc/init.d/tcpquotad : Program to check the TCP link
#
# Written by Turbo Fredriksson <turbo@tripnet.se>.
#
# $Header: /usr/lib/cvs/root/tcpquota/confs/tcpquota.init,v 1.10 1998/10/15 23:55:55 turbo Exp $
#
# $Log: tcpquota.init,v $
# Revision 1.10  1998/10/15 23:55:55  turbo
# Wrong path to the daemon... '/usr/local/sbin' instead of
# '/usr/sbin'.
#
# Revision 1.9  1998/08/11 02:22:39  turbo
# No need to export the variables MSQL_UNIX_PORT and MSQL_TCP_PORT, they are
# set in the config file.
#
# Revision 1.8  1998/05/24 20:39:24  turbo
# No real changes, just retabbed the 'done' part to get a cleaner output when
# updating binaries/scripts...
#
# Revision 1.7  1998/04/13 13:46:35  turbo
# Added the environment variables 'MSQL_UNIX_PORT' and 'MSQL_TCP_PORT'.
# That might help with the problem with not being able to connect to
# the mSQL daemon on localhost...
# Uncommented just incase...
#
# Revision 1.6  1998/03/13 15:07:17  turbo
# Duhhh.... Just a space in an echo... Boring!
#
# Revision 1.5  1998/02/15 17:37:59  turbo
# * Added the function 'restart' which stops the daemon and then starts it again...
# * Added the phony target 'force-reload'...
#
# Revision 1.4  1997/12/01 14:20:26  turbo
# 'Better looking startup'... (Yeah, right! :)
#
# Revision 1.3  1997/08/14 17:29:28  turbo
# Some one have forgot to echo 'done.' after the masquerading is done...
#
# Revision 1.2  1997/01/19 05:54:43  marbud
# Lagt in Header och log.. Samt uppstart av forwarding default rule = deny
#
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/tcpquotad
NAME=tcpquotad

test -f $DAEMON || exit 0

# Set run_tcpquotad to 1 to start daemon at boot or 0 to disable it.
run_tcpquotad=1

case "$1" in
  start)
    if [ $run_tcpquotad = 1 ]
    then
      # Deny forwarding and masquerade localnet to all..
      echo -n "Configuring masqueradeing...        "
      /sbin/ipfwadm -Fp deny
      echo "done."

      # Start the tcquota daemon...
      start-stop-daemon --start --verbose \
	--pidfile /var/run/$NAME.pid --exec $DAEMON 2> /dev/null
    fi
    ;;

  stop)
    # Stop the tcpquota daemon...
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid
    ;;

  restart)
    echo -n "Restarting TCPQuota daemon... "
    start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid
    start-stop-daemon --start --verbose \
	--pidfile /var/run/$NAME.pid --exec $DAEMON 2> /dev/null
    echo "done."
    ;;

  force-reload)
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}"
    exit 1
esac

exit 0
