5 # Required-Start: $local_fs $network $remote_fs $syslog
6 # Required-Stop: $local_fs $network $remote_fs $syslog
7 # Default-Start: 2 3 4 5
9 # Short-Description: start and stop the Frr routing suite
10 # Description: Frr is a routing suite for IP routing protocols like
11 # BGP, OSPF, RIP and others. This script contols the main
12 # daemon "frr" as well as the individual protocol daemons.
16 PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
17 D_PATH
="@CFG_SBIN@" # /usr/lib/frr
18 C_PATH
="@CFG_SYSCONF@" # /etc/frr
19 V_PATH
="@CFG_STATE@" # /var/run/frr
20 VTYSH
="@vtysh_bin@" # /usr/bin/vtysh
21 FRR_USER
="@enable_user@" # frr
22 FRR_GROUP
="@enable_group@" # frr
23 FRR_VTY_GROUP
="@enable_vty_group@" # frrvty
25 # Local Daemon selection may be done by using /etc/frr/daemons.
26 # See /usr/share/doc/frr/README.Debian.gz for further information.
27 # Keep zebra first and do not list watchfrr!
28 DAEMONS
="zebra bgpd ripd ripngd ospfd ospf6d isisd babeld pimd ldpd nhrpd eigrpd sharpd pbrd staticd bfdd fabricd"
30 RELOAD_SCRIPT
="$D_PATH/frr-reload.py"
32 if [ -e /lib
/lsb
/init-functions
]; then
33 .
/lib
/lsb
/init-functions
36 if [ -f $D_PATH/ssd
]; then
39 SSD
=`which start-stop-daemon`
42 # Print the name of the pidfile.
48 # Print the name of the vtysh.
56 test -n "$FRR_USER" && chown
"$FRR_USER" "$1"
57 test -n "$FRR_GROUP" && chgrp
"$FRR_GROUP" "$1"
60 # Check if daemon is started by using the pidfile.
63 [ ! -e `pidfile $1` ] && return 3
64 if [ -n "$2" ] && [ "$2" == "log" ]; then
65 status_of_proc
-p `pidfile $1` $1 $1 && return 0 ||
return $?
67 kill -0 `cat \`pidfile
$1\
`` 2> /dev
/null ||
return 1
72 # Loads the config via vtysh -b if configured to do so.
75 # Rember, that all variables have been incremented by 1 in convert_daemon_prios()
76 if [ "$vtysh_enable" = 2 -a -f $C_PATH/frr.conf
]; then
81 # Check if the daemon is activated and if its executable and config files
84 # returns: 0=ok, 1=error
87 if [ $1 != "watchfrr" -a $1 != "vtysh_enable" ]; then
88 # check for daemon binary
89 if [ ! -x "$D_PATH/$1" ]; then return 1; fi
92 # If the integrated config file is used the others are not checked.
93 if [ -r "$C_PATH/frr.conf" ]; then
97 # vtysh_enable has no config file nor binary so skip check.
98 # (Not sure why vtysh_enable is in this list but does not hurt)
99 if [ $1 != "watchfrr" -a $1 != "vtysh_enable" ]; then
100 # check for config file
102 if [ ! -r "$C_PATH/$1-$2.conf" ]; then
103 touch "$C_PATH/$1-$2.conf"
104 chownfrr
"$C_PATH/$1-$2.conf"
106 elif [ ! -r "$C_PATH/$1.conf" ]; then
107 touch "$C_PATH/$1.conf"
108 chownfrr
"$C_PATH/$1.conf"
114 # Starts the server if it's not alrady running according to the pid file.
115 # The Frr daemons creates the pidfile when starting.
119 if [ "$1" = "watchfrr" ]; then
121 # We may need to restart watchfrr if new daemons are added and/or
123 if started
"$1" ; then
126 # Echo only once. watchfrr is printed in the stop above
133 --pidfile=`pidfile $1` \
134 --exec "$D_PATH/$1" \
136 "${watchfrr_options[@]}"
138 elif [ -n "$2" ]; then
140 if ! check_daemon
$1 $2 ; then
141 echo -n " (binary does not exist)"
147 --pidfile=`pidfile $1-$2` \
148 --exec "$D_PATH/$1" \
150 `eval echo "$""$1""_options"` -n "$2"
152 if ! check_daemon
$1; then
153 echo -n " (binary does not exist)"
157 if [ "$valgrind_enable" = "yes" ]; then
160 --pidfile=`pidfile $1` \
162 -- --trace-children=no
--leak-check=full
--log-file=/var
/log
/frr
/$1-valgrind.log
$D_PATH/$1 \
163 `eval echo "$""$1""_options"`
167 --pidfile=`pidfile $1` \
168 --exec "$D_PATH/$1" \
170 `eval echo "$""$1""_options"`
174 # Start the staticd automatically
175 if [ "$1" = "zebra" ]; then
176 echo -n "starting staticd since zebra is running"
177 if ! check_daemon staticd
; then
178 echo -n " (binary does not exist)"
184 --pidfile=`pidfile staticd` \
185 --exec "$D_PATH/staticd" \
187 `eval echo "$"staticd"_options"`
191 # Stop the daemon given in the parameter, printing its name to the terminal.
202 if ! started
"$inst" ; then
206 PIDFILE
=`pidfile $inst`
207 PID
=`cat $PIDFILE 2>/dev/null`
208 kill -2 $PID 2>/dev
/null
210 # Now we have to wait until $DAEMON has _really_ stopped.
212 if test -n "$PID" && kill -0 $PID 2>/dev
/null
; then
214 while kill -0 $PID 2>/dev
/null
; do
216 if [ $cnt -gt 60 ]; then
217 # Waited 120 secs now, fail.
224 rm -f `pidfile $inst`
225 rm -f `vtyfile $inst`
227 if [ "$1" = "zebra" ]; then
228 echo -n "Stopping staticd since zebra is running"
234 # Converts values from /etc/frr/daemons to all-numeric values.
235 convert_daemon_prios
()
237 for name
in $DAEMONS zebra vtysh_enable watchfrr_enable
; do
238 # First, assign the value set by the user to $value
239 eval value
=\
${${name}:0:3}
241 # Daemon not activated or entry missing?
242 if [ "$value" = "no" -o "$value" = "" ]; then value
=0; fi
244 # These strings parsed for backwards compatibility.
245 if [ "$value" = "yes" -o "$value" = "true" ]; then
249 # Zebra is threatened special. It must be between 0=off and the first
250 # user assigned value "1" so we increase all other enabled daemons' values.
251 if [ "$name" != "zebra" -a "$value" -gt 0 ]; then value
=`expr "$value" + 1`; fi
253 # If e.g. name is zebra then we set "zebra=yes".
258 # Starts watchfrr for all wanted daemons.
266 # Start the monitor daemon only if desired.
267 if [ 0 -eq "$watchfrr_enable" ]; then
271 # Check variable type
272 if ! declare -p watchfrr_options |
grep -q '^declare \-a'; then
274 echo "ERROR: The variable watchfrr_options from /etc/frr/debian.cnf must be a BASH array!"
275 echo "ERROR: Please convert config file and restart!"
279 # Which daemons have been started?
281 for daemon_name
in $DAEMONS; do
282 eval daemon_prio
=\$
$daemon_name
283 if [ "$daemon_prio" -gt 0 ]; then
284 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
285 if [ -n "$daemon_inst" ]; then
286 for inst
in ${daemon_inst}; do
287 eval "inst_disable=\${${daemon_name}_${inst}}"
288 if [ -z ${inst_disable} ] ||
[ ${inst_disable} != 0 ]; then
289 if check_daemon
$daemon_name $inst; then
290 watchfrr_options
+=("${daemon_name}-${inst}")
295 if check_daemon
$daemon_name; then
296 watchfrr_options
+=($daemon_name)
303 # Start if at least one daemon is activated.
304 if [ $found_one -eq 1 ]; then
313 echo -n "Stopping Frr monitor daemon:"
318 # Stops all daemons that have a lower level of priority than the given.
319 # (technically if daemon_prio >= wanted_prio)
328 if [ -n "$2" ] && [[ "$2" =~
(.
*)-(.
*) ]]; then
329 daemon
=${BASH_REMATCH[1]}
330 inst
=${BASH_REMATCH[2]}
336 daemon_list
=${daemon:-$DAEMONS}
338 echo -n "Stopping Frr daemons (prio:$wanted_prio):"
340 for prio_i
in `seq 10 -1 $wanted_prio`; do
341 for daemon_name
in $daemon_list; do
342 eval daemon_prio
=\
${${daemon_name}:0:3}
344 if [ $daemon_prio -eq $prio_i ]; then
345 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
346 if [ -n "$daemon_inst" ]; then
347 for i
in ${daemon_inst}; do
348 if [ -n "$inst" ] && [ "$i" == "$inst" ]; then
349 stop
"$daemon_name" "$inst"
350 elif [ x
"$inst" == x
]; then
351 stop
"$daemon_name" "$i"
362 if [ -z "$inst" ]; then
363 # Now stop other daemons that're prowling, coz the daemons file changed
364 echo -n "Stopping other frr daemons"
365 if [ -n "$daemon" ]; then
366 eval "file_list_suffix="$V_PATH"/"$daemon*""
368 eval "file_list_suffix="$V_PATH/*""
370 for pidfile
in $file_list_suffix.pid
; do
371 PID
=`cat $pidfile 2>/dev/null`
372 ${SSD} --stop --quiet --oknodo --pidfile "$pidfile"
378 echo -n "Removing remaining .vty files"
379 for vtyfile
in $file_list_suffix.vty
; do
386 # Starts all daemons that have a higher level of priority than the given.
387 # (technically if daemon_prio <= wanted_prio)
397 if [ -n "$2" ] && [[ "$2" =~
(.
*)-(.
*) ]]; then
398 daemon
=${BASH_REMATCH[1]}
399 inst
=${BASH_REMATCH[2]}
405 daemon_list
=${daemon:-$DAEMONS}
407 for prio_i
in `seq 1 $wanted_prio`; do
408 for daemon_name
in $daemon_list; do
409 eval daemon_prio
=\$
${daemon_name}
411 if [ $daemon_prio -eq $prio_i ]; then
412 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
413 if [ -n "$daemon_inst" ]; then
414 if [ `echo "$daemon_inst" | wc -w` -gt ${MAX_INSTANCES} ]; then
415 echo "Max instances supported is ${MAX_INSTANCES}. Aborting"
418 # Check if we're starting again by switching from single instance
420 if started
"$daemon_name"; then
421 PIDFILE
=`pidfile $daemon_name`
423 --stop --quiet --oknodo \
424 --pidfile "$PIDFILE" \
425 --exec "$D_PATH/$daemon_name"
431 for i
in ${daemon_inst}; do
432 if [ -n "$inst" ] && [ "$i" == "$inst" ]; then
433 start
"$daemon_name" "$inst"
434 elif [ x
"$inst" == x
]; then
435 start
"$daemon_name" "$i"
439 # Check if we're starting again by switching from
440 # single instance to MI version
441 eval "file_list_suffix="$V_PATH"/"$daemon_name-*""
442 for pidfile
in $file_list_suffix.pid
; do
443 ${SSD} --stop --quiet --oknodo --pidfile "$pidfile"
446 for vtyfile
in $file_list_suffix.vty
; do
462 local failed_status
=0
464 if [ -n "$1" ] && [[ "$1" =~
(.
*)-(.
*) ]]; then
465 daemon
=${BASH_REMATCH[1]}
466 inst
=${BASH_REMATCH[2]}
471 daemon_list
=${daemon:-$DAEMONS}
473 # Which daemons have been started?
474 for daemon_name
in $daemon_list; do
475 eval daemon_prio
=\$
$daemon_name
476 if [ "$daemon_prio" -gt 0 ]; then
477 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
478 if [ -n "$daemon_inst" ]; then
479 for i
in ${daemon_inst}; do
480 if [ -n "$inst" -a "$inst" = "$i" ]; then
481 started
"$1" "log" || failed_status
=$?
482 elif [ -z "$inst" ]; then
483 started
"$daemon_name-$i" "log" || failed_status
=$?
487 started
"$daemon_name" "log" || failed_status
=$?
492 # All daemons that need to have been started are up and running
493 return $failed_status
496 #########################################################
498 #########################################################
500 # Config broken but script must exit silently.
501 [ ! -r "$C_PATH/daemons" ] && exit 0
505 .
"$C_PATH/daemons.conf"
507 # Read configuration variable file if it is present
508 [ -r /etc
/default
/frr
] && .
/etc
/default
/frr
510 MAX_INSTANCES
=${MAX_INSTANCES:=5}
512 # Set priority of un-startable daemons to 'no' and substitute 'yes' to '0'
515 if [ ! -d $V_PATH ]; then
516 echo "Creating $V_PATH"
522 if [ -n "$3" ] && [ "$3" != "all" ]; then
524 elif [ -n "$2" ] && [ "$2" != "all" ]; then
530 # Try to load this necessary (at least for 2.6) module.
531 if [ -d /lib
/modules
/`uname -r` ] ; then
532 echo "Loading capability module if not yet done."
533 set +e
; LC_ALL
=C modprobe
-a capability
2>&1 |
egrep -v "(not found|Can't locate)"; set -e
538 if [ "$2" != "watchfrr" ]; then
545 1|
2|
3|
4|
5|
6|
7|
8|
9|
10)
546 # Stop/start daemons for the appropriate priority level
553 # Stop all daemons at level '0' or 'stop'
555 if [ "$dmn" != "watchfrr" ]; then
556 [ -n "${dmn}" ] && eval "${dmn/-/_}=0"
560 if [ -z "$dmn" -o "$dmn" = "zebra" ]; then
561 echo "Removing all routes made by FRR."
562 # Specific values for each proto can be found
563 # in /etc/iproute2/rt_protos as well as FRR
564 # specific ones in /etc/iproute2/rt_protos.d
565 # Additionally if a new protocol is added
566 # we need to add it here as well as
567 # in rt_netlink.h( follow the directions! )
568 ip route flush proto
4
569 ip route flush proto
11
570 ip route flush proto
42
571 ip route flush proto
186
572 ip route flush proto
187
573 ip route flush proto
188
574 ip route flush proto
189
575 ip route flush proto
190
576 ip route flush proto
191
577 ip route flush proto
192
578 ip route flush proto
193
579 ip route flush proto
194
580 ip route flush proto
195
581 ip route flush proto
196
582 ip route flush proto
197
584 [ -n "$dmn" ] && eval "${dmn/-/_}=0"
590 # Just apply the commands that have changed, no restart necessary
591 if [ ! -x "$RELOAD_SCRIPT" ]; then
592 echo "Please install frr-pythontools package. Required for reload"
596 NEW_CONFIG_FILE
="${2:-$C_PATH/frr.conf}"
597 [ ! -r $NEW_CONFIG_FILE ] && echo "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1
598 echo "Applying only incremental changes to running configuration from frr.conf"
599 "$RELOAD_SCRIPT" --reload $C_PATH/frr.conf
608 restart|force-reload
)
615 echo "Usage: /etc/init.d/frr {start|stop|status|reload|restart|force-reload|<priority>} [daemon]"
616 echo " E.g. '/etc/init.d/frr 5' would start all daemons with a prio 1-5."
617 echo " reload applies only modifications from the running config to all daemons."
618 echo " reload neither restarts starts any daemon nor starts any new ones."
619 echo " Read /usr/share/doc/frr/README.Debian for details."
624 echo "Exiting from the script"