#!/bin/sh # vim:textwidth=80:tabstop=4:shiftwidth=4:smartindent:autoindent # Source function library. . /etc/rc.d/init.d/functions CLIARGS="$*" # Grab any args passed to safe_radiusd DUMPDROP=/tmp SLEEPSECS=5 RADIUSBINDIR=/usr/local/sbin/ prog=radiusd [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog exec=${exec:=/usr/local/sbin/$prog} config_dir=${config_dir:=/usr/local/etc/raddb} config=${config:=$config_dir/radiusd.conf} pidfile=${pidfile:=/usr/local/var/run/$prog/$prog.pid} lockfile=${lockfile:=/var/lock/subsys/radiusd} # run radius with this priority PRIORITY=0 # check if module is installed if [ ! -e /usr/local/lib/rlm_m2.so ]; then echo "M2 Radius modules are not installed. $0 will exit now." exit 1 fi # check if radius is already running if [ "$1" != "FORCE" ]; then ISRUNNING=`ps -ef | grep -v safe | grep -v grep | grep -v init | grep -v service | grep -v rc | grep radiusd | wc -l` if test "`echo $ISRUNNING`" = "1" ; then echo "Radius is already running. $0 will exit now." exit 1 fi fi # set limits ulimit -c unlimited ulimit -d unlimited ulimit -f unlimited ulimit -i unlimited ulimit -n 999999 ulimit -q unlimited ulimit -u unlimited ulimit -v unlimited ulimit -x unlimited ulimit -s 244 ulimit -l unlimited # check if core dump dir is writeable if test ! -w "${DUMPDROP}" ; then echo "Cannot write to ${DUMPDROP}" >&2 exit 1 fi run_radiusd() { # loop everytime radius exits with non zero return code while :; do # execute radius cd /tmp $exec -f -d $config_dir # -f means run in foreground - without it radius is capable to use > 100% cpu (several cores?). This sadly disables safe_radiusd functionality #$exec -d $config_dir # get exit status EXITSTATUS=$? echo "Radiusd ended with exit status $EXITSTATUS" # check exit status if test "x$EXITSTATUS" = "x0" ; then # properly shutdown.... echo "Radiusd shutdown normally." exit 0 elif test "0$EXITSTATUS" -gt "128" ; then EXITSIGNAL=$(($EXITSTATUS - 128)) echo "Radiusd exited on signal $EXITSIGNAL" if test "x$NOTIFY" != "x" ; then echo "Radiusd exited on signal $EXITSIGNAL. Might want to take a peek." fi # get most recent core dump file from /tmp MOST_RECENT_FILE=`find /tmp/core.* -cmin -1 | grep -v radiusd | tail -n 1` if [ ! -z $MOST_RECENT_FILE ]; then mv $MOST_RECENT_FILE $MOST_RECENT_FILE.radiusd fi # leave max 10 latest core dump files rm -f `ls -t /tmp/core.*.radiusd 2> /dev/null | awk 'NR>5'` else echo "Radiusd died with code $EXITSTATUS" # get most recent core dump file from /tmp MOST_RECENT_FILE=`find /tmp/core.* -cmin -1 | grep -v radiusd | tail -n 1` if [ ! -z $MOST_RECENT_FILE ]; then mv /tmp/$MOST_RECENT_FILE /tmp/$MOST_RECENT_FILE.radiusd fi # leave max 10 latest core dump files rm -f `ls -t /tmp/core.*.radiusd 2> /dev/null | awk 'NR>5'` fi echo "Automatically restarting Radiusd." sleep $SLEEPSECS done } run_radiusd &