#!/bin/bash
#
# radiusd Start/Stop the radius daemon.
# chkconfig: 2345 98 10
# description: Cistron Radius is a "Remote Dial In Out Server"
# config: /etc/raddb/clients
# probe: false
# processname: radiusd
# pidfile: /var/run/radiusd.pid

RADIUSD=/usr/sbin/radiusd
RADRELAY=/usr/sbin/radrelay
DESC="Cistron radius server"
LOCKF=/var/lock/subsys/radiusd

# 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"

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

test -f $RADIUSD || exit 0
test -f /etc/raddb/clients || exit 0

case "$1" in
  start)
	[ -f /var/log/radutmp ] || touch /var/log/radutmp
	gprintf "Starting %s: Cistron radius server"
	if [ -x "$RADRELAY" ] && [ -n "$RADRELAY_ARGS" ]
	then
		gprintf "radrelay "
		daemon $RADRELAY $RADRELAY_ARGS
	fi
	daemon $RADIUSD $RADIUS_ARGS
	gprintf "radiusd.\n"
	touch $LOCKF
	;;
  stop)
	[ -z "$2" ] && echo -n "Stopping $DESC: "
	if [ -x "$RADRELAY" ] && [ -n "$RADRELAY_ARGS" ]
	then
		[ -z "$2" ] && echo -n "radrelay "
		killproc $RADRELAY 2>/dev/null
	fi
	killproc $RADIUSD 2> /dev/null
	[ -z "$2" ] && echo "radiusd."
	rm -f $LOCKF
	;;
  status)
        status $RADIUSD
 	;;
  reload)
	gprintf "Reloading %s configuration files.\n" "$DESC"
	killproc -1 $RADIUSD
	;;
  restart)
	$0 stop quiet
	sleep 3
	$0 start
	;;
  *)
	gprintf "Usage: %s {start|stop|status|reload|restart}\n" "$0"
	exit 1
esac

exit 0
