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
21 VTYSH
="@vtysh_bin@" # /usr/bin/vtysh
22 FRR_USER
="@enable_user@" # frr
23 FRR_GROUP
="@enable_group@" # frr
24 FRR_VTY_GROUP
="@enable_vty_group@" # frrvty
25 FRR_CONFIG_MODE
="@enable_configfile_mask@" # 0600
26 FRR_DEFAULT_PROFILE
="@DFLT_NAME@" # traditional / datacenter
28 # Local Daemon selection may be done by using /etc/frr/daemons.
29 # See /usr/share/doc/frr/README.Debian.gz for further information.
30 # Keep zebra first and do not list watchfrr!
31 DAEMONS
="mgmtd zebra bgpd ripd ripngd ospfd ospf6d isisd babeld pimd pim6d ldpd nhrpd eigrpd sharpd pbrd staticd bfdd fabricd vrrpd pathd"
33 RELOAD_SCRIPT
="$D_PATH/frr-reload.py"
35 if [ -e /lib
/lsb
/init-functions
]; then
36 .
/lib
/lsb
/init-functions
39 if [ -f $D_PATH/ssd
]; then
42 SSD
=`which start-stop-daemon`
45 # Print the name of the pidfile.
51 # Print the name of the vtysh.
57 # Check if daemon is started by using the pidfile.
60 [ ! -e `pidfile $1` ] && return 3
61 if [ -n "$2" ] && [ "$2" == "log" ]; then
62 status_of_proc
-p `pidfile $1` $1 $1 && return 0 ||
return $?
64 kill -0 `cat \`pidfile
$1\
`` 2> /dev
/null ||
return 1
69 # Loads the config via vtysh -b if configured to do so.
72 # Rember, that all variables have been incremented by 1 in convert_daemon_prios()
73 if [ "$vtysh_enable" = 2 -a -f $C_PATH/frr.conf
]; then
78 # Check if the daemon is activated and if its executable and config files
81 # returns: 0=ok, 1=error
84 if [ $1 != "watchfrr" -a $1 != "vtysh_enable" ]; then
85 # check for daemon binary
86 if [ ! -x "$D_PATH/$1" ]; then return 1; fi
89 # If the integrated config file is used the others are not checked.
90 if [ -r "$C_PATH/frr.conf" ]; then
94 # vtysh_enable has no config file nor binary so skip check.
95 # (Not sure why vtysh_enable is in this list but does not hurt)
96 if [ $1 != "watchfrr" -a $1 != "vtysh_enable" ]; then
97 # check for config file
99 if [ ! -r "$C_PATH/$1-$2.conf" ]; then
100 install -g "$FRR_GROUP" -o "$FRR_USER" -m "$FRR_CONFIG_MODE" /dev
/null
"$C_PATH/$1-$2.conf"
102 elif [ ! -r "$C_PATH/$1.conf" ]; then
103 install -g "$FRR_GROUP" -o "$FRR_USER" -m "$FRR_CONFIG_MODE" /dev
/null
"$C_PATH/$1.conf"
109 # Starts the server if it's not alrady running according to the pid file.
110 # The Frr daemons creates the pidfile when starting.
117 ulimit -n $MAX_FDS > /dev
/null
2> /dev
/null
118 if [ "$dmn" = "watchfrr" ]; then
120 # We may need to restart watchfrr if new daemons are added and/or
122 if started
"$dmn" ; then
125 # Echo only once. watchfrr is printed in the stop above
129 eval "set - $watchfrr_options"
132 --pidfile=`pidfile $dmn` \
133 --exec "$D_PATH/$dmn" \
137 elif [ -n "$inst" ]; then
138 echo -n " $dmn-$inst"
139 if ! check_daemon
$dmn $inst ; then
140 echo -n " (binary does not exist)"
146 --pidfile=`pidfile $dmn-$inst` \
147 --exec "$D_PATH/$dmn" \
149 `eval echo "$""$dmn""_options"` $frr_global_options -n "$inst"
151 if ! check_daemon
$dmn; then
152 echo -n " (binary does not exist)"
156 if [ "$valgrind_enable" = "yes" ]; then
159 --pidfile=`pidfile $dmn` \
161 -- --trace-children=no
--leak-check=full
--log-file=/var
/log
/frr
/$dmn-valgrind.log
$D_PATH/$dmn \
162 `eval echo "$""$dmn""_options"` $frr_global_options
166 --pidfile=`pidfile $dmn` \
167 --exec "$D_PATH/$dmn" \
169 `eval echo "$""$dmn""_options"` $frr_global_options
173 # Start the staticd automatically
174 if [ "$dmn" = "zebra" ]; then
175 echo -n "starting staticd since zebra is running"
176 if ! check_daemon staticd
; then
177 echo -n " (binary does not exist)"
183 --pidfile=`pidfile staticd` \
184 --exec "$D_PATH/staticd" \
186 `eval echo "$"staticd"_options"` $frr_global_options
190 # Stop the daemon given in the parameter, printing its name to the terminal.
201 if ! started
"$inst" ; then
205 PIDFILE
=`pidfile $inst`
206 PID
=`cat $PIDFILE 2>/dev/null`
207 kill -2 $PID 2>/dev
/null
209 # Now we have to wait until $DAEMON has _really_ stopped.
211 if test -n "$PID" && kill -0 $PID 2>/dev
/null
; then
213 while kill -0 $PID 2>/dev
/null
; do
215 if [ $cnt -gt 60 ]; then
216 # Waited 120 secs now, fail.
223 rm -f `pidfile $inst`
224 rm -f `vtyfile $inst`
226 if [ "$1" = "zebra" ]; then
227 echo -n "Stopping staticd since zebra is running"
233 # Converts values from /etc/frr/daemons to all-numeric values.
234 convert_daemon_prios
()
236 for name
in $DAEMONS zebra vtysh_enable watchfrr_enable
; do
237 # First, assign the value set by the user to $value
238 eval value
=\
${${name}:0:3}
240 # Daemon not activated or entry missing?
241 if [ "$value" = "no" -o "$value" = "" ]; then value
=0; fi
243 # These strings parsed for backwards compatibility.
244 if [ "$value" = "yes" -o "$value" = "true" ]; then
248 # Zebra is threatened special. It must be between 0=off and the first
249 # user assigned value "1" so we increase all other enabled daemons' values.
250 if [ "$name" != "zebra" -a "$value" -gt 0 ]; then value
=`expr "$value" + 1`; fi
252 # If e.g. name is zebra then we set "zebra=yes".
257 # Starts watchfrr for all wanted daemons.
265 # Start the monitor daemon only if desired.
266 if [ 0 -eq "$watchfrr_enable" ]; then
270 # Check variable type
271 if declare -p watchfrr_options |
grep -q '^declare \-a'; then
273 watchfrr_options
="${watchfrr_options[@]}"
276 # Which daemons have been started?
278 for daemon_name
in $DAEMONS; do
279 eval daemon_prio
=\$
$daemon_name
280 if [ "$daemon_prio" -gt 0 ]; then
281 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
282 if [ -n "$daemon_inst" ]; then
283 for inst
in ${daemon_inst}; do
284 eval "inst_disable=\${${daemon_name}_${inst}}"
285 if [ -z ${inst_disable} ] ||
[ ${inst_disable} != 0 ]; then
286 if check_daemon
$daemon_name $inst; then
287 watchfrr_options
="$watchfrr_options ${daemon_name}-${inst}"
292 if check_daemon
$daemon_name; then
293 watchfrr_options
="$watchfrr_options $daemon_name"
300 # Start if at least one daemon is activated.
301 if [ $found_one -eq 1 ]; then
310 echo -n "Stopping Frr monitor daemon:"
315 # Stops all daemons that have a lower level of priority than the given.
316 # (technically if daemon_prio >= wanted_prio)
325 if [ -n "$2" ] && [[ "$2" =~
(.
*)-(.
*) ]]; then
326 daemon
=${BASH_REMATCH[1]}
327 inst
=${BASH_REMATCH[2]}
333 daemon_list
=${daemon:-$DAEMONS}
335 echo -n "Stopping Frr daemons (prio:$wanted_prio):"
337 for prio_i
in `seq 10 -1 $wanted_prio`; do
338 for daemon_name
in $daemon_list; do
339 eval daemon_prio
=\
${${daemon_name}:0:3}
341 if [ $daemon_prio -eq $prio_i ]; then
342 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
343 if [ -n "$daemon_inst" ]; then
344 for i
in ${daemon_inst}; do
345 if [ -n "$inst" ] && [ "$i" == "$inst" ]; then
346 stop
"$daemon_name" "$inst"
347 elif [ x
"$inst" == x
]; then
348 stop
"$daemon_name" "$i"
359 if [ -z "$inst" ]; then
360 # Now stop other daemons that're prowling, coz the daemons file changed
361 echo -n "Stopping other frr daemons"
362 if [ -n "$daemon" ]; then
363 eval "file_list_suffix="$V_PATH"/"$daemon*""
365 eval "file_list_suffix="$V_PATH/*""
367 for pidfile
in $file_list_suffix.pid
; do
368 PID
=`cat $pidfile 2>/dev/null`
369 ${SSD} --stop --quiet --oknodo --pidfile "$pidfile"
375 echo -n "Removing remaining .vty files"
376 for vtyfile
in $file_list_suffix.vty
; do
383 # Starts all daemons that have a higher level of priority than the given.
384 # (technically if daemon_prio <= wanted_prio)
394 if [ -n "$2" ] && [[ "$2" =~
(.
*)-(.
*) ]]; then
395 daemon
=${BASH_REMATCH[1]}
396 inst
=${BASH_REMATCH[2]}
402 daemon_list
=${daemon:-$DAEMONS}
404 for prio_i
in `seq 1 $wanted_prio`; do
405 for daemon_name
in $daemon_list; do
406 eval daemon_prio
=\$
${daemon_name}
408 if [ $daemon_prio -eq $prio_i ]; then
409 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
410 if [ -n "$daemon_inst" ]; then
411 if [ `echo "$daemon_inst" | wc -w` -gt ${MAX_INSTANCES} ]; then
412 echo "Max instances supported is ${MAX_INSTANCES}. Aborting"
415 # Check if we're starting again by switching from single instance
417 if started
"$daemon_name"; then
418 PIDFILE
=`pidfile $daemon_name`
420 --stop --quiet --oknodo \
421 --pidfile "$PIDFILE" \
422 --exec "$D_PATH/$daemon_name"
428 for i
in ${daemon_inst}; do
429 if [ -n "$inst" ] && [ "$i" == "$inst" ]; then
430 start
"$daemon_name" "$inst"
431 elif [ x
"$inst" == x
]; then
432 start
"$daemon_name" "$i"
436 # Check if we're starting again by switching from
437 # single instance to MI version
438 eval "file_list_suffix="$V_PATH"/"$daemon_name-*""
439 for pidfile
in $file_list_suffix.pid
; do
440 ${SSD} --stop --quiet --oknodo --pidfile "$pidfile"
443 for vtyfile
in $file_list_suffix.vty
; do
459 local failed_status
=0
461 if [ -n "$1" ] && [[ "$1" =~
(.
*)-(.
*) ]]; then
462 daemon
=${BASH_REMATCH[1]}
463 inst
=${BASH_REMATCH[2]}
468 daemon_list
=${daemon:-$DAEMONS}
470 # Which daemons have been started?
471 for daemon_name
in $daemon_list; do
472 eval daemon_prio
=\$
$daemon_name
473 if [ "$daemon_prio" -gt 0 ]; then
474 eval "daemon_inst=\${${daemon_name}_instances//,/ }"
475 if [ -n "$daemon_inst" ]; then
476 for i
in ${daemon_inst}; do
477 if [ -n "$inst" -a "$inst" = "$i" ]; then
478 started
"$1" "log" || failed_status
=$?
479 elif [ -z "$inst" ]; then
480 started
"$daemon_name-$i" "log" || failed_status
=$?
484 started
"$daemon_name" "log" || failed_status
=$?
489 # All daemons that need to have been started are up and running
490 return $failed_status
493 #########################################################
495 #########################################################
497 # Config broken but script must exit silently.
498 [ ! -r "$C_PATH/daemons" ] && exit 0
502 if [ -e "$C_PATH/daemons.conf" ]; then
503 .
"$C_PATH/daemons.conf"
506 # Read configuration variable file if it is present
507 [ -r /etc
/default
/frr
] && .
/etc
/default
/frr
509 if test -z "$frr_profile"; then
510 # try to autodetect config profile
511 if test -d /etc
/cumulus
; then
512 frr_profile
=datacenter
513 # elif test ...; then
514 # -- add your distro/system here
515 elif test -n "$FRR_DEFAULT_PROFILE"; then
516 frr_profile
="$FRR_DEFAULT_PROFILE"
519 test -n "$frr_profile" && frr_global_options
="$frr_global_options -F $frr_profile"
521 MAX_INSTANCES
=${MAX_INSTANCES:=5}
523 # Set priority of un-startable daemons to 'no' and substitute 'yes' to '0'
526 if [ ! -d $V_PATH ]; then
527 echo "Creating $V_PATH"
528 install -g "$FRR_GROUP" -o "$FRR_USER" -m "$FRR_CONFIG_MODE" -d "$V_PATH"
529 chmod gu
+x
"${V_PATH}"
532 if [ -n "$3" ] && [ "$3" != "all" ]; then
534 elif [ -n "$2" ] && [ "$2" != "all" ]; then
540 # Try to load this necessary (at least for 2.6) module.
541 if [ -d /lib
/modules
/`uname -r` ] ; then
542 echo "Loading capability module if not yet done."
543 set +e
; LC_ALL
=C modprobe
-a capability
2>&1 |
egrep -v "(not found|Can't locate)"; set -e
548 if [ "$2" != "watchfrr" ]; then
555 1|
2|
3|
4|
5|
6|
7|
8|
9|
10)
556 # Stop/start daemons for the appropriate priority level
563 # Stop all daemons at level '0' or 'stop'
565 if [ "$dmn" != "watchfrr" ]; then
566 [ -n "${dmn}" ] && eval "${dmn/-/_}=0"
570 if [ -n "$dmn" -a "$dmn" != "zebra" ]; then
571 [ -n "$dmn" ] && eval "${dmn/-/_}=0"
577 # Just apply the commands that have changed, no restart necessary
578 if [ ! -x "$RELOAD_SCRIPT" ]; then
579 echo "Please install frr-pythontools package. Required for reload"
583 NEW_CONFIG_FILE
="${2:-$C_PATH/frr.conf}"
584 [ ! -r $NEW_CONFIG_FILE ] && echo "Unable to read new configuration file $NEW_CONFIG_FILE" && exit 1
585 echo "Applying only incremental changes to running configuration from frr.conf"
586 "$RELOAD_SCRIPT" --reload --bindir "$B_PATH" --confdir "$C_PATH" --rundir "$V_PATH" "$C_PATH/frr.conf"
595 restart|force-reload
)
602 echo "Usage: /etc/init.d/frr {start|stop|status|reload|restart|force-reload|<priority>} [daemon]"
603 echo " E.g. '/etc/init.d/frr 5' would start all daemons with a prio 1-5."
604 echo " reload applies only modifications from the running config to all daemons."
605 echo " reload neither restarts starts any daemon nor starts any new ones."
606 echo " Read /usr/share/doc/frr/README.Debian for details."
611 echo "Exiting from the script"