#!/bin/sh # # Startup script for ripd # will be run by rc.zebra, # so don't need to run this script from the command line # # processname: ripd # pidfile: /var/run/ripd.pid # config: /etc/ripd/ripd.conf # chkconfig: 35 21 79 # description: Start and stop ripd # Global definitions DEMON=ripd PID_FILE="/var/run/${DEMON}.pid" #------------------------------------- COUNT=`grep -c ^ripd /etc/services` if [ "$COUNT" = "0" ] then "$0 needs ripd 2602/tcp entry in /etc/services, exiting" exit 1 fi ripd_start() { #is $DEMON running? #(can have multiple copies, but should only have one) COUNT=`netstat -an | grep -c /tmp/.${DEMON}$` if [ "$COUNT" = "0" ] then echo -n "$DEMON " /usr/sbin/$DEMON & else echo "$0: $DEMON already running, nothing done" fi } ripd_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 } # See how we were called. case "$1" in start) ripd_start ;; stop) ripd_stop ;; restart) ripd_stop #don't know if this is neccessary, but just in case sleep 1 ripd_start ;; 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