#!/bin/sh
#
# radiusd	Start the radius daemon.
#
#		This is a script suitable for the Debian Linux distribution.
#		Copy it to /etc/init.d/radiusd, make it executable, and execute
#		"update-rc.d radiusd defaults 50".
#

RADIUSD=/usr/sbin/radiusd
WATCHER=/usr/sbin/radwatch
NAME1=radiusd
NAME2=radwatch

test -f $RADIUSD || exit 0

case "$1" in
  start)
	if [ ! -f /var/log/radutmp ]
	then
		:>/var/log/radutmp
	fi
	echo -n 'Starting AAA server: '
	if [ -x $WATCHER ]
	then
		echo -n "radwatch "
		start-stop-daemon --start --quiet --startas $WATCHER \
			--pidfile /var/run/$NAME2.pid --exec $RADIUSD -- -y
	else
		start-stop-daemon --start --quiet \
			--pidfile /var/run/$NAME1.pid --exec $RADIUSD -- -y
	fi
	echo "radiusd."
	;;
  stop)
	[ -z "$2" ] && echo -n 'Stopping AAA server: '
	if [ -x $WATCHER ]
	then
		[ -z "$2" ] && echo -n "radwatch "
		start-stop-daemon --stop --quiet \
			--pidfile /var/run/$NAME2.pid -- exec $RADWATCH
		#killall -9 radwatch 2>/dev/null
	else
		start-stop-daemon --stop --quiet \
			--pidfile /var/run/$NAME1.pid --exec $RADIUSD
	fi
	#killall radiusd 2>/dev/null
	[ -z "$2" ] && echo "radiusd."
	;;
  reload|restart)
	sh /etc/init.d/radiusd stop quiet
	sleep 3
	/etc/init.d/radiusd start
	;;
  *)
        echo "Usage: /etc/init.d/$NAME1 {start|stop|reload}"
        exit 1
esac

exit 0
