#!/bin/sh
#
# chkconfig:	- 88 10
# description:	Start/Stop the RADIUS server daemon
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#    Copyright (C) 2001 The FreeRADIUS Project   http://www.freeradius.org
#

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

RADIUSD=/usr/sbin/radiusd
LOCKF=/var/lock/subsys/freeradius
CONFIG=/etc/raddb/radiusd.conf

[ -f "$RADIUSD" ] || exit 0
[ -f "$CONFIG" ] || exit 0

RETVAL=0
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f "$LOCKF" ]; then
		msg_starting RADIUS
		daemon "$RADIUSD"
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch "$LOCKF"
	else
		msg_already_running RADIUS
	fi
	;;
  stop)
	# Stop daemons.
	if [ -f "$LOCKF" ]; then
		msg_stopping RADIUS
		killproc "$RADIUSD"
		rm -f "$LOCKF" > /dev/null 2>&1
	else
		msg_not_running RADIUS
	fi
	;;
  status)
	status radiusd
	exit $?
	;;
  reload)
	if [ -f "$LOCKF" ]; then
		msg_reloading RADIUS
		killproc "$RADIUSD" -HUP
		RETVAL=$?
	else
		msg_not_running RADIUS >&2
		exit 7
	fi
	;;
  restart|force-reload)
	$0 stop
	sleep 3
	$0 start
	RETVAL=$?
	;;
#  condrestart)
#	if [ -f $LOCKF ]; then
#		$0 stop
#		sleep 3
#		$0 start
#		RETVAL=$?
#	fi
#	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
