daemon: streamline Quagga startup

Currently, all Quagga daemons are started concurrently by their
respective CORE services, using "quaggaboot.sh" generated by the
'zebra' service. However, all routing services depend on 'zebra'
already running, and 'vtysh' depends on ALL other Quagga services
before it can push configuration from the common "Quagga.conf" to
all running daemons (see "waitforvtyfiles()" in "quaggaboot.sh").

The spinwait+timeout based implementation of "waitforvtyfiles()"
may, depending on load, give up too early and fail to configure
all Quagga daemons.

This patch streamlines the way Quagga daemons are started, by
launching them all from the 'zebra' service. The correct sequence
is to first launch the 'zebra' daemon itself, then proceed with
all routing daemons, and finish with a call to "vtysh -b" which
configures all running daemons.

The list of all applicable daemons to launch is obtained using
'grep' from Quagga.conf, in the same way "waitforvtyfiles()" used
to discover which *.vty files to look for in /var/run/quagga/.

The startup command for all services other than 'zebra' becomes
empty, and "quaggaboot.sh" issues a warning on attempts to have
it launch any other daemon.

Signed-off-by: Gabriel Somlo <glsomlo@cert.org>
This commit is contained in:
Gabriel Somlo 2017-01-12 16:40:45 -05:00
parent 003044d98b
commit 6609d2c394

View file

@ -170,21 +170,6 @@ confcheck()
fi fi
} }
waitforvtyfiles()
{
for f in "$@"; do
count=1
until [ -e $QUAGGA_STATE_DIR/$f ]; do
if [ $count -eq 10 ]; then
echo "ERROR: vty file not found: $QUAGGA_STATE_DIR/$f" >&2
return 1
fi
sleep 0.1
count=$(($count + 1))
done
done
}
bootdaemon() bootdaemon()
{ {
QUAGGA_SBIN_DIR=$(searchforprog $1 $QUAGGA_SBIN_SEARCH) QUAGGA_SBIN_DIR=$(searchforprog $1 $QUAGGA_SBIN_SEARCH)
@ -196,53 +181,47 @@ bootdaemon()
flags="" flags=""
if [ "$1" != "zebra" ]; then
waitforvtyfiles zebra.vty
fi
if [ "$1" = "xpimd" ] && \\ if [ "$1" = "xpimd" ] && \\
grep -E -q '^[[:space:]]*router[[:space:]]+pim6[[:space:]]*$' $QUAGGA_CONF; then grep -E -q '^[[:space:]]*router[[:space:]]+pim6[[:space:]]*$' $QUAGGA_CONF; then
flags="$flags -6" flags="$flags -6"
fi fi
$QUAGGA_SBIN_DIR/$1 $flags -u $QUAGGA_USER -g $QUAGGA_GROUP -d $QUAGGA_SBIN_DIR/$1 $flags -u $QUAGGA_USER -g $QUAGGA_GROUP -d
if [ "$?" != "0" ]; then
echo "ERROR: Quagga's '$1' daemon failed to start!:"
return 1
fi
} }
bootvtysh() bootquagga()
{ {
QUAGGA_BIN_DIR=$(searchforprog $1 $QUAGGA_BIN_SEARCH) QUAGGA_BIN_DIR=$(searchforprog 'vtysh' $QUAGGA_BIN_SEARCH)
if [ "z$QUAGGA_BIN_DIR" = "z" ]; then if [ "z$QUAGGA_BIN_DIR" = "z" ]; then
echo "ERROR: Quagga's '$1' daemon not found in search path:" echo "ERROR: Quagga's 'vtysh' program not found in search path:"
echo " $QUAGGA_SBIN_SEARCH" echo " $QUAGGA_BIN_SEARCH"
return 1 return 1
fi fi
vtyfiles="zebra.vty" bootdaemon "zebra"
for r in rip ripng ospf6 ospf bgp babel; do for r in rip ripng ospf6 ospf bgp babel; do
if grep -q "^router \<${r}\>" $QUAGGA_CONF; then if grep -q "^router \<${r}\>" $QUAGGA_CONF; then
vtyfiles="$vtyfiles ${r}d.vty" bootdaemon "${r}d"
fi fi
done done
if grep -E -q '^[[:space:]]*router[[:space:]]+pim6?[[:space:]]*$' $QUAGGA_CONF; then if grep -E -q '^[[:space:]]*router[[:space:]]+pim6?[[:space:]]*$' $QUAGGA_CONF; then
vtyfiles="$vtyfiles xpimd.vty" bootdaemon "xpimd"
fi fi
# wait for Quagga daemon vty files to appear before invoking vtysh
waitforvtyfiles $vtyfiles
$QUAGGA_BIN_DIR/vtysh -b $QUAGGA_BIN_DIR/vtysh -b
} }
confcheck if [ "$1" != "zebra" ]; then
if [ "x$1" = "x" ]; then echo "WARNING: '$1': all Quagga daemons are launched by the 'zebra' service!"
echo "ERROR: missing the name of the Quagga daemon to boot"
exit 1 exit 1
elif [ "$1" = "vtysh" ]; then
bootvtysh $1
else
bootdaemon $1
fi fi
confcheck
bootquagga
""" % (cls._configs[0], quagga_sbin_search, quagga_bin_search, \ """ % (cls._configs[0], quagga_sbin_search, quagga_bin_search, \
QUAGGA_STATE_DIR, QUAGGA_USER, QUAGGA_GROUP) QUAGGA_STATE_DIR, QUAGGA_USER, QUAGGA_GROUP)
@ -311,7 +290,7 @@ class Ospfv2(QuaggaService):
unified Quagga.conf file. unified Quagga.conf file.
''' '''
_name = "OSPFv2" _name = "OSPFv2"
_startup = ("sh quaggaboot.sh ospfd",) _startup = ()
_shutdown = ("killall ospfd", ) _shutdown = ("killall ospfd", )
_validate = ("pidof ospfd", ) _validate = ("pidof ospfd", )
_ipv4_routing = True _ipv4_routing = True
@ -382,7 +361,7 @@ class Ospfv3(QuaggaService):
unified Quagga.conf file. unified Quagga.conf file.
''' '''
_name = "OSPFv3" _name = "OSPFv3"
_startup = ("sh quaggaboot.sh ospf6d",) _startup = ()
_shutdown = ("killall ospf6d", ) _shutdown = ("killall ospf6d", )
_validate = ("pidof ospf6d", ) _validate = ("pidof ospf6d", )
_ipv4_routing = True _ipv4_routing = True
@ -486,7 +465,7 @@ class Bgp(QuaggaService):
having the same AS number. having the same AS number.
''' '''
_name = "BGP" _name = "BGP"
_startup = ("sh quaggaboot.sh bgpd",) _startup = ()
_shutdown = ("killall bgpd", ) _shutdown = ("killall bgpd", )
_validate = ("pidof bgpd", ) _validate = ("pidof bgpd", )
_custom_needed = True _custom_needed = True
@ -511,7 +490,7 @@ class Rip(QuaggaService):
''' The RIP service provides IPv4 routing for wired networks. ''' The RIP service provides IPv4 routing for wired networks.
''' '''
_name = "RIP" _name = "RIP"
_startup = ("sh quaggaboot.sh ripd",) _startup = ()
_shutdown = ("killall ripd", ) _shutdown = ("killall ripd", )
_validate = ("pidof ripd", ) _validate = ("pidof ripd", )
_ipv4_routing = True _ipv4_routing = True
@ -534,7 +513,7 @@ class Ripng(QuaggaService):
''' The RIP NG service provides IPv6 routing for wired networks. ''' The RIP NG service provides IPv6 routing for wired networks.
''' '''
_name = "RIPNG" _name = "RIPNG"
_startup = ("sh quaggaboot.sh ripngd",) _startup = ()
_shutdown = ("killall ripngd", ) _shutdown = ("killall ripngd", )
_validate = ("pidof ripngd", ) _validate = ("pidof ripngd", )
_ipv6_routing = True _ipv6_routing = True
@ -558,7 +537,7 @@ class Babel(QuaggaService):
protocol for IPv6 and IPv4 with fast convergence properties. protocol for IPv6 and IPv4 with fast convergence properties.
''' '''
_name = "Babel" _name = "Babel"
_startup = ("sh quaggaboot.sh babeld",) _startup = ()
_shutdown = ("killall babeld", ) _shutdown = ("killall babeld", )
_validate = ("pidof babeld", ) _validate = ("pidof babeld", )
_ipv6_routing = True _ipv6_routing = True
@ -588,7 +567,7 @@ class Xpimd(QuaggaService):
PIM multicast routing based on XORP. PIM multicast routing based on XORP.
''' '''
_name = 'Xpimd' _name = 'Xpimd'
_startup = ('sh quaggaboot.sh xpimd',) _startup = ()
_shutdown = ('killall xpimd', ) _shutdown = ('killall xpimd', )
_validate = ('pidof xpimd', ) _validate = ('pidof xpimd', )
_ipv4_routing = True _ipv4_routing = True
@ -622,7 +601,7 @@ class Vtysh(CoreService):
_name = "vtysh" _name = "vtysh"
_group = "Quagga" _group = "Quagga"
_startindex = 45 _startindex = 45
_startup = ("sh quaggaboot.sh vtysh",) _startup = ()
_shutdown = () _shutdown = ()
@classmethod @classmethod