#!/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
RADRELAY=/usr/sbin/radrelay
DESC="Advanced radius server"
NAME1=radiusd
NAME2=radrelay

# These are the defaults.
RADIUS_ARGS="-y"

# This is useful if you want to replicate accounting packets
# to another radius server - see README.radrelay
#RADIUS_ARGS="-y -w -F %N/detail -F detail.rep"
#RADRELAY_ARGS="-a /var/log/radacct XX.SERVER.HERE.XX detail.rep"

test -f $RADIUSD || exit 0

case "$1" in
  start)
	if [ ! -f /var/log/radutmp ]
	then
		:>/var/log/radutmp
	fi
	echo -n "Starting $DESC:"
	if [ -x "$RADRELAY" ] &&[ -n "$RADRELAY_ARGS" ]
	then
		echo -n " radrelay"
		start-stop-daemon --start --quiet \
			--pidfile /var/run/$NAME2.pid \
			--exec $RADRELAY -- $RADRELAY_ARGS
	fi
	echo -n " radiusd"
	start-stop-daemon --start --quiet \
		--pidfile /var/run/$NAME1.pid \
		--exec $RADIUSD -- $RADIUS_ARGS
	echo "."
	;;
  stop)
	[ -z "$2" ] && echo -n "Stopping $DESC:"
	if [ -x "$RADRELAY" ] &&[ -n "$RADRELAY_ARGS" ]
	then
		[ -z "$2" ] && echo -n " radrelay"
		start-stop-daemon --stop --quiet \
			--pidfile /var/run/$NAME2.pid --exec $RADRELAY
	fi
	[ -z "$2" ] && echo -n " radiusd"
	start-stop-daemon --stop --quiet \
		--pidfile /var/run/$NAME1.pid --exec $RADIUSD
	[ -z "$2" ] && echo "."
	;;
  reload|force-reload)
	echo "Reloading $DESC configuration files."
	start-stop-daemon --stop --signal 1 --quiet --pidfile \
		/var/run/$NAME1.pid --exec $RADIUSD
	;;
  restart)
	sh /etc/init.d/radiusd stop quiet
	sleep 3
	/etc/init.d/radiusd start
	;;
  *)
        echo "Usage: /etc/init.d/$NAME1 {start|stop|reload|restart}"
        exit 1
esac

exit 0
