Ensure we leave room for the trailing NUL
[freeradius.git] / scripts / rc.radiusd.in
index 8776856..4cc04ab 100755 (executable)
@@ -2,76 +2,98 @@
 #
 # radiusd      Start the radius daemon.
 #
-#              This is a script suitable for the Debian Linux distribution.
-#              Copy it to /etc/init.d/radiusd, make it executable, and
-#              execute "update-rc.d radiusd defaults 50".
+#    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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+#
+#    Copyright (C) 2001-2008 The FreeRADIUS Project http://www.freeradius.org
 
 prefix=@prefix@
 exec_prefix=@exec_prefix@
 sbindir=@sbindir@
 localstatedir=@localstatedir@
 logdir=@logdir@
-rundir=${localstatedir}/run
+rundir=${localstatedir}/run/radiusd
+sysconfdir=@sysconfdir@
+
+#
+#  If you have issues with OpenSSL, uncomment these next lines.
+#
+#  Something similar may work for MySQL, and you may also
+#  have to LD_PRELOAD libz.so
+#
+#LD_LIBRARY_PATH=@OPENSSL_LIBS@
+#LD_RUN_PATH=@OPENSSL_LIBS@:
+#LD_PRELOAD=@OPENSSL_LIBS@libcrypto.so
+export LD_LIBRARY_PATH LD_RUN_PATH LD_PRELOAD
 
 RADIUSD=$sbindir/radiusd
-WATCHER=$sbindir/radwatch
-DESC="Freeradius server"
-NAME1=radiusd
-NAME2=radwatch
+RADDBDIR=@raddbdir@
+DESC="FreeRADIUS"
 
-ARGS="-y"
+#
+#  See 'man radiusd' for details on command-line options.
+#
+ARGS=""
 
 test -f $RADIUSD || exit 0
+test -f $RADDBDIR/radiusd.conf || exit 0
+
+#if [ ! -d $rundir ] ; then
+#    mkdir $rundir
+#    chown radmin:radius $rundir
+#    chmod 775 $rundir
+#fi
+#
+#if [ ! -d $logdir ] ; then
+#    mkdir $logdir
+#    chown radmin:radius $logdir
+#    chmod 770 $logdir
+#    chmod g+s $logdir
+#fi
+#
+#if [ ! -f $logdir/radius.log ]; then
+#        touch $logdir/radius.log
+#fi
+#
+#chown radmin:radius $logdir/radius.log
+#chmod 660 $logdir/radius.log
 
 case "$1" in
   start)
-       if [ ! -f $logdir/radutmp ]
-       then
-               >$logdir/radutmp
-       fi
        echo -n "Starting $DESC:"
-       if [ -x $WATCHER ]
-       then
-               echo -n " radwatch"
-               start-stop-daemon --start --quiet --startas $WATCHER \
-                       --pidfile $rundir/$NAME2.pid --exec $RADIUSD -- $ARGS
-               # and the watcher starts radiusd.
-               echo -n " radiusd"
-       else
-               echo -n " radiusd"
-               start-stop-daemon --start --quiet \
-                       --pidfile $rundir/$NAME1.pid --exec $RADIUSD -- $ARGS
-       fi
-       echo "."
+       $RADIUSD $ARGS
+       echo "radiusd"
        ;;
   stop)
        [ -z "$2" ] && echo -n "Stopping $DESC: "
-       if [ -x $WATCHER ]
-       then
-               [ -z "$2" ] && echo -n "radwatch "
-               start-stop-daemon --stop --quiet \
-                       --pidfile $rundir/$NAME2.pid -- exec $RADWATCH
-               # but we have to stop radiusd manually.
-               killall radiusd 2>/dev/null
-       else
-               start-stop-daemon --stop --quiet \
-                       --pidfile $rundir/$NAME1.pid --exec $RADIUSD
-       fi
+        [ -f $rundir/radiusd.pid ] && kill -TERM `cat $rundir/radiusd.pid`
        [ -z "$2" ] && echo "radiusd."
        ;;
   reload|force-reload)
        echo "Reloading $DESC configuration files."
-       start-stop-daemon --stop --signal 1 --quiet --pidfile \
-               $rundir/$NAME1.pid --exec $RADIUSD
+       [ -f $rundir/radiusd.pid ] && kill -HUP `cat $rundir/radiusd.pid`
        ;;
   restart)
-       sh /etc/init.d/radiusd stop quiet
+       sh $0 stop quiet
        sleep 3
-       /etc/init.d/radiusd start
+       sh $0 start
+       ;;
+  check)
+       $RADIUSD -C $ARGS
        ;;
   *)
-        echo "Usage: /etc/init.d/$NAME1 {start|stop|reload|restart}"
+        echo "Usage: /etc/init.d/$RADIUS {start|stop|reload|restart|check}"
         exit 1
 esac