#!/bin/sh # # Startup script for zebra # This runs subscripts (eg for bgpd), # so don't need to start dependant demons separately # # processname: zebra # pidfile: /var/run/zebra.pid # config: /etc/zebra/zebra.conf # chkconfig: 35 21 79 # description: Start and stop zebra # Global definitions DEMON=zebra PID_FILE="/var/run/${DEMON}.pid" #----------------------------------- #check that we can detect zebra by its name COUNT=`grep -c ^zebra /etc/services` if [ "$COUNT" = "0" ] then "$0 needs zebra 2601/tcp and zebrasrv 2600/tcp entries in /etc/services, exiting" exit 1 fi zebra_start() { #you can start multiple copies of zebra #even though only the first will bind to the port # #test to see if already running COUNT=`netstat -an | grep -c /tmp/.${DEMON}$` if [ "$COUNT" = "0" ] then echo -n "$DEMON " /usr/sbin/$DEMON & else echo "$0: $DEMON already running, no action taken" fi #/etc/rc.d/rc.bgpd start #/etc/rc.d/rc.ospfd start /etc/rc.d/rc.ripd start } zebra_stop() { #echo -n "Shutting down $DEMON: " #have to shutdown bgpd first /etc/rc.d/rc.ripd stop #/etc/rc.d/rc.ospfd stop #/etc/rc.d/rc.bgpd stop if [ -f $PID_FILE ] then kill `cat $PID_FILE` rm -rf $PID_FILE #if things have got out of step, #then the PID_FILE #doesn't neccessarily have the PID of $DEMON, #and the above command will try to kill a process that doesn't exist. #did we kill a process that existed if [ "$?" = "0" ] then true else killall $DEMON rm -rf $PID_FILE fi logger -p local0.notice "$DEMON: stop" else #no PID file found COUNT=`netstat -an | grep -c /tmp/.${DEMON}$` if [ "$COUNT" = "0" ] then logger "$0: no $DEMON to kill" else killall $DEMON rm -rf $PID_FILE logger -p local0.notice "$DEMON: stop" fi fi #if by mistake, you had started a zebra by hand, #after having started one with this script, #you would still have a zebra running. COUNT=`netstat -an | grep -c /tmp/.$DEMON$` if [ "$COUNT" != "0" ] then echo "$0: $DEMON still running, rerunning zebra_stop" zebra_stop fi } # See how we were called. case "$1" in start) zebra_start ;; stop) zebra_stop ;; restart) zebra_stop #don't know if this is neccessary, but just in case sleep 1 zebra_start ;; reload) /etc/rc.d/rc.ripd reload #/etc/rc.d/rc.bgpd reload #/etc/rc.d/rc.ospfd reload #echo -n "Reloading $DEMON config: " kill -HUP `cat $PID_FILE` if [ "$?" != "0" ] then echo "$0; reload failed, executing restart" $0 restart fi ;; *) echo "Usage: $0 {start|stop|restart|reload}" exit 1 esac exit 0