#!/bin/sh
#
# radiusd       This shell script takes care of starting and stopping
#               radius daemon.
# Author: Cyril Zlachevsky <mazay@donapex.net>
#
# chkconfig: 345 98 12
# description:  This script is used to start/stop RADIUS daemon.
# description(ru):     /
#                RADIUS.

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

RADIUSD=/usr/sbin/radiusd
WATCHER=/usr/sbin/radwatch
LOCKF=/var/lock/subsys/radiusd

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

RETVAL=0

case "$1" in
  start)
        [ -f /var/log/radutmp ] || touch /var/log/radutmp
        echo -n 'Starting RADIUSD server: '
        if [ -x $WATCHER ]
        then
                daemon $WATCHER $RADIUSD -y
        else
                daemon $RADIUSD -y
        fi
        touch $LOCKF
        echo
	RETVAL=$?
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down RADIUS: "
	killproc $WATCHER
	rm -f /var/run/radiusd.pid
	echo
	RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f $LOCKF
        ;;
  status)
	status radiusd
	RETVAL=$?
	;;
  reload)
	echo -n "Reloading RADIUS config: "
	killproc $RADIUSD -HUP

	echo
	;;
  restart)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
        echo "Usage: radiusd {start|stop|status|restart|reload}"
        exit 1
esac

exit $RETVAL
