[Xorp-users] suggested init.d scripts to start xorp anyone?

Alain Fauconnet alain@ait.ac.th
Fri, 3 Mar 2006 09:33:27 +0700


On Thu, Mar 02, 2006 at 02:38:27PM -0800, Pavlin Radoslavov wrote:
> > I am running xorp, for multicast routing only, on a fedora core 4 box that
> > is doing nothing else.
> > 
> > Does anyone have a suggested script to place in /etc/init.d to start it
> > in an appropriate way?
> 
> Unfortunately, we (XORP) don't have such script, but we would like
> to have one in our tree. Ideally, we should have a solution for
> other OS-es as well. Contributions are welcome.

Here's the one I use on a RH 7.3-based router box.
(I know RH 7.3 is paleolitic, it's self-maintained from source now)
Comments welcome.

Greets,
_Alain_

---------------------------- cut here -------------------------------
#!/bin/bash
#
# xorp		This shell script takes care of starting and stopping
#               the xorp service.
#
# chkconfig: 345 57 49
# description: xorp is a network routing daemon.

# Change history:
# ~~~~~~~~~~~~~~
# 22-Mar-2005 AlainF	Rotate the log file, kill all remaining
#			processes at stop
# 04-Apr-2005 AlainF	Keep 3 rotated log files as .1, .2, .3

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

XORPDIR=/usr/local/xorp
BINDIR=${XORPDIR}/bin
LOGFILE=/var/log/xorp.log
OPTIONS=-v

[ -f $BINDIR/xorp_rtrmgr ] || exit 0

prog="xorp"

start() {
    echo -n $"Starting $prog: "
    # Rotate log files
    if [ -f ${LOGFILE} ]; then
	[ -f ${LOGFILE}.2 ] && /bin/mv ${LOGFILE}.2 ${LOGFILE}.3
	[ -f ${LOGFILE}.1 ] && /bin/mv ${LOGFILE}.1 ${LOGFILE}.2
	/bin/mv ${LOGFILE} ${LOGFILE}.1
    fi
    # Change current directory to Xorp's root
    if [ -d ${XORPDIR} ]; then
        cd ${XORPDIR}
    else
        exit 1
    fi
    $BINDIR/xorp_rtrmgr $OPTIONS 2>&1 | /bin/cat >$LOGFILE  &
    RETVAL=$?
    if [ $RETVAL = 0 ]; then
        success $"Starting $prog"
    else
        failure  $"Starting $prog"
    fi
    echo
    return $RETVAL
}

stop() {
    echo -n $"Stopping $prog: "
    # Kill master process
    pid=`/bin/ps auxww | /bin/grep ${XORPDIR} | /bin/grep xorp_rtrmgr|\
           /bin/grep -v grep | /usr/bin/awk '{print $2}'`
    if [ "$pid" != "" ]; then 
        kill -15 ${pid}
    else
        # No master process?!? try proceeding anyway
        echo -n " (no master process found) "
    fi
    # Give it a while to signal other processes
    sleep 15
    # Kill any remaining processes
    pids=`/bin/ps auxww | /bin/grep ${XORPDIR} | /bin/grep -v grep |\
        /usr/bin/awk '{print $2}'`
    if [ "$pids" != "" ]; then
        kill -15 ${pids}
    fi
    success $"Stopping $prog"
    echo
    return 0
}

case "$1" in
	start)
	    start
	    ;;

	stop)
	    stop
	    ;;

	status)
	    status $prog
	    ;;
	restart)
	    stop
	    start
	    ;;

	*)
	    echo "Usage: $prog {start|stop|restart|status}"
	    exit 1

esac

exit 0

---------------------------- cut here -------------------------------