patch from David Kerry <dk@snti.com> to properly define variables
[freeradius.git] / scripts / radwatch.in
1 #! /bin/sh
2 #
3 # radwatch      Script to watch RADIUS. Sends mail to root and
4 #               restarts radiusd when it dies [which ofcourse
5 #               never happens :)]
6 #
7 # Version:      $Id$
8 #
9
10 prefix=@prefix@
11 exec_prefix=@exec_prefix@
12 sbindir=@sbindir@
13 localstatedir=@localstatedir@
14 logdir=@logdir@
15 rundir=${localstatedir}/run
16
17 MAILTO=root
18 RADIUSD=$sbindir/radiusd
19
20 exec >> $logdir/radwatch.log 2>&1
21
22 # get the path to the radiusd
23 if [ "$1" ] && [ -x "$1" ]
24 then
25         RADIUSD=$1
26         shift
27 fi
28
29 cd $logdir
30 [ -d $logdir/radacct ] && cd $logdir/radacct
31 ulimit -c unlimited
32
33 (
34         trap 'echo `date`: exit; kill `cat $rundir/radiusd.pid`; exit 0' TERM
35         trap "" HUP TSTP
36
37         while :
38         do
39                 # Use `wait', otherwise the trap doesn't work.
40                 $RADIUSD -f $* &
41                 wait
42                 exec >> $logdir/radwatch.log 2>&1
43                 echo "`date`: Radius died, restarting.."
44                 date | mail -s "Radius died, restarting.." $MAILTO
45                 sleep 10
46         done
47 ) &
48
49 echo "$!" > $rundir/radwatch.pid
50
51 sleep 1