#!/bin/sh
# Start/stop the FreeRADIUS daemon.

set -e

PROG="freeradius"
PROGRAM="/usr/sbin/freeradius"
PIDFILE="/var/run/freeradius/freeradius.pid"
DESCR="FreeRADIUS daemon"

test -f $PROGRAM || exit 0

case "$1" in
	start)
		echo -n "Starting $DESCR: "
		start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $PROGRAM
		if [ $? = 0 ]; then
			echo "$PROG."
		else
			echo "(failed!  run '$PROGRAM -x' to find out why.)"
			exit 1
		fi
		;;
	stop)
		echo -n "Stopping $DESCR: "
		start-stop-daemon --stop --quiet --pidfile $PIDFILE
		echo "$PROG."
		;;
	restart)
		echo -n "Restarting $DESCR: "
		$0 stop
		sleep 2
		$0 start
		;;
	reload | force-reload) 
		echo -n "Reloading configuration files for $DESCR"
		start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE
		sleep 2
		ps --pid $(cat $PIDFILE) > /dev/null || exit 1
		echo "."
		;;
	*)
		echo "Usage: /etc/init.d/freeradius start|stop|restart|reload|force-reload"
		exit 1 
esac

exit 0
