#!/bin/sh # # Startup script for ospfd # will be run by rc.zebra, # so don't need to run this script from the command line # # processname: ospfd # pidfile: /var/run/ospfd.pid # config: /etc/ospfd/ospfd.conf # chkconfig: 35 21 79 # description: Start and stop ospfd # Global definitions DEMON=ospfd PID_FILE="/var/run/${DEMON}.pid" #------------------------------------- COUNT=`grep -c ^ospfd /etc/services` if [ "$COUNT" = "0" ] then "$0 needs ospfd 2604/tcp entry in /etc/services, exiting" exit 1 fi ospfd_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 } ospfd_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) ospfd_start ;; stop) ospfd_stop ;; restart) ospfd_stop #don't know if this is neccessary, but just in case sleep 1 ospfd_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