3 # This is a "library" of sorts for use by the other FRR shell scripts. It
4 # has most of the daemon start/stop logic, but expects the following shell
5 # functions/commands to be provided by the "calling" script:
11 # (coincidentally, these are LSB standard functions.)
13 # Sourcing this file in a shell script will load FRR config variables but
14 # not perform any action. Note there is an "exit 1" if the main config
15 # file does not exist.
17 # This script should be installed in @CFG_SBIN@/frrcommon.sh
19 PATH
=/bin
:/usr
/bin
:/sbin
:/usr
/sbin
20 D_PATH
="@CFG_SBIN@" # /usr/lib/frr
21 C_PATH
="@CFG_SYSCONF@" # /etc/frr
22 V_PATH
="@CFG_STATE@" # /var/run/frr
23 VTYSH
="@vtysh_bin@" # /usr/bin/vtysh
24 FRR_USER
="@enable_user@" # frr
25 FRR_GROUP
="@enable_group@" # frr
26 FRR_VTY_GROUP
="@enable_vty_group@" # frrvty
27 FRR_DEFAULT_PROFILE
="@DFLT_NAME@" # traditional / datacenter
29 # ORDER MATTERS FOR $DAEMONS!
31 # - watchfrr does NOT belong in this list
33 DAEMONS
="zebra bgpd ripd ripngd ospfd ospf6d isisd babeld pimd ldpd nhrpd eigrpd sharpd pbrd staticd bfdd fabricd vrrpd"
34 RELOAD_SCRIPT
="$D_PATH/frr-reload.py"
41 [ -n "$watchfrr_debug" ] ||
return 0
43 printf '%s %s(%s):' "`date +%Y-%m-%dT%H:%M:%S.%N`" "$0" $$
>&2
44 # this is to show how arguments are split regarding whitespace & co.
45 # (e.g. for use with `debug "message" "$@"`)
46 while [ $# -gt 0 ]; do
47 printf ' "%s"' "$1" >&2
54 [ -n "$FRR_USER" ] && chown
"$FRR_USER" "$1"
55 [ -n "$FRR_GROUP" ] && chgrp
"$FRR_GROUP" "$1"
59 [ "$1" = "watchfrr" ] && return 0
60 [ -r "$C_PATH/frr.conf" ] ||
return 0
62 "$VTYSH" -b -n -d "$1"
69 # note this sets global variables ($dmninst, $daemon, $inst)
71 daemon
="${dmninst%-*}"
73 [ "$daemon" != "$dmninst" ] && inst
="${dmninst#*-}"
77 # note $1 and $2 specify names for global variables to be set
78 local enabled disabled evar dvar
84 for daemon
in $DAEMONS; do
86 eval inst
=\$
${daemon}_instances
87 [ "$daemon" = zebra
-o "$daemon" = staticd
] && cfg
=yes
88 if [ -n "$cfg" -a "$cfg" != "no" -a "$cfg" != "0" ]; then
89 if ! daemon_prep
"$daemon" "$inst"; then
92 debug
"$daemon enabled"
93 enabled
="$enabled $daemon"
94 if [ -n "$inst" ]; then
95 debug
"$daemon multi-instance $inst"
99 enabled
="$enabled $daemon-$i"
104 debug
"$daemon disabled"
105 disabled
="$disabled $daemon"
109 enabled
="${enabled# }"
110 disabled
="${disabled# }"
111 [ -z "$evar" ] && echo "$enabled"
112 [ -n "$evar" ] && eval $evar="\"$enabled\""
113 [ -n "$dvar" ] && eval $dvar="\"$disabled\""
117 # individual daemon management
121 local daemon inst cfg
124 [ "$daemon" = "watchfrr" ] && return 0
125 [ -x "$D_PATH/$daemon" ] ||
{
126 log_failure_msg
"cannot start $daemon${inst:+ (instance $inst)}: daemon binary not installed"
129 [ -r "$C_PATH/frr.conf" ] && return 0
131 cfg
="$C_PATH/$daemon${inst:+-$inst}.conf"
132 if [ ! -r "$cfg" ]; then
140 local dmninst daemon inst args instopt wrap bin
143 ulimit -n $MAX_FDS > /dev
/null
2> /dev
/null
144 daemon_prep
"$daemon" "$inst" ||
return 1
145 if test ! -d "$V_PATH"; then
150 eval wrap
="\$${daemon}_wrap"
151 bin
="$D_PATH/$daemon"
152 instopt
="${inst:+-n $inst}"
153 eval args
="\$${daemon}_options"
155 if eval "$all_wrap $wrap $bin -d $frr_global_options $instopt $args"; then
156 log_success_msg
"Started $dmninst"
159 log_failure_msg
"Failed to start $dmninst!"
164 local dmninst daemon inst pidfile vtyfile pid cnt fail
167 pidfile
="$V_PATH/$daemon${inst:+-$inst}.pid"
168 vtyfile
="$V_PATH/$daemon${inst:+-$inst}.vty"
170 [ -r "$pidfile" ] || fail
="pid file not found"
171 [ -z "$fail" ] && pid
="`cat \"$pidfile\"`"
172 [ -z "$fail" -a -z "$pid" ] && fail
="pid file is empty"
173 [ -n "$fail" ] ||
kill -0 "$pid" 2>/dev
/null || fail
="pid $pid not running"
175 if [ -n "$fail" ]; then
176 log_failure_msg
"Cannot stop $dmninst: $fail"
183 while kill -0 "$pid" 2>/dev
/null
; do
185 [ $
(( cnt
-= 1 )) -gt 0 ] ||
break
187 if kill -0 "$pid" 2>/dev
/null
; then
188 log_failure_msg
"Failed to stop $dmninst, pid $pid still running"
192 log_success_msg
"Stopped $dmninst"
199 local dmninst daemon inst pidfile pid fail
202 pidfile
="$V_PATH/$daemon${inst:+-$inst}.pid"
204 [ -r "$pidfile" ] ||
return 3
205 pid
="`cat \"$pidfile\"`"
206 [ -z "$pid" ] && return 1
207 kill -0 "$pid" 2>/dev
/null ||
return 1
214 if [ "$rv" -eq 0 ]; then
215 log_success_msg
"Status of $1: running"
217 log_failure_msg
"Status of $1: FAILED"
223 # all-daemon commands
228 for dmninst
in $daemons; do
229 daemon_start
"$dmninst"
236 daemon_list daemons disabled
237 [ "$1" = "--reallyall" ] && daemons
="$daemons $disabled"
240 for dmninst
in $daemons; do
241 reversed
="$dmninst $reversed"
244 for dmninst
in $reversed; do
245 daemon_stop
"$dmninst" &
258 for dmninst
in $daemons; do
259 print_status
"$dmninst" || fail
=1
270 [ -r "$oldcfg" ] ||
return 0
271 [ -s "$oldcfg" ] ||
return 0
272 grep -v '^[[:blank:]]*\(#\|$\)' "$oldcfg" > /dev
/null ||
return 0
274 log_warning_msg
"Reading deprecated $oldcfg. Please move its settings to $C_PATH/daemons and remove it."
276 # save off settings from daemons for the OR below
277 for dmn
in $DAEMONS; do eval "_new_$dmn=\${$dmn:-no}"; done
281 # OR together the daemon enabling options between config files
282 for dmn
in $DAEMONS; do eval "test \$_new_$dmn != no && $dmn=\$_new_$dmn; unset _new_$dmn"; done
285 [ -r "$C_PATH/daemons" ] ||
{
286 log_failure_msg
"cannot run $@: $C_PATH/daemons does not exist"
291 load_old_config
"$C_PATH/daemons.conf"
292 load_old_config
"/etc/default/frr"
293 load_old_config
"/etc/sysconfig/frr"
295 if { declare -p watchfrr_options
2>/dev
/null || true
; } |
grep -q '^declare \-a'; then
296 log_warning_msg
"watchfrr_options contains a bash array value." \
297 "The configured value is intentionally ignored since it is likely wrong." \
298 "Please remove or fix the setting."
299 unset watchfrr_options
302 if test -z "$frr_profile"; then
303 # try to autodetect config profile
304 if test -d /etc
/cumulus
; then
305 frr_profile
=datacenter
306 # elif test ...; then
307 # -- add your distro/system here
308 elif test -n "$FRR_DEFAULT_PROFILE"; then
309 frr_profile
="$FRR_DEFAULT_PROFILE"
312 test -n "$frr_profile" && frr_global_options
="$frr_global_options -F $frr_profile"
315 # other defaults and dispatch
321 debug
"frrcommon_main" "$@"
326 if [ "$1" = "all" -o -z "$1" ]; then
338 start
) daemon_start
"$@";;
339 stop
) daemon_stop
"$@";;