Skip to content

Commit aab37b7

Browse files
authored
[FRR] Create a separate script to wait zebra to be ready to receive connections (sonic-net#6519)
The requirement for zebra to be ready to accept connections is a generic problem that is not specific to bgpd. Making the script to wait for zebra socket a separate script and let bgpd and staticd to wait for zebra socket.
1 parent 7f222e7 commit aab37b7

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

dockers/docker-fpm-frr/Dockerfile.j2

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ COPY ["TSA", "/usr/bin/TSA"]
5454
COPY ["TSB", "/usr/bin/TSB"]
5555
COPY ["TSC", "/usr/bin/TSC"]
5656
COPY ["files/supervisor-proc-exit-listener", "/usr/bin"]
57-
COPY ["bgpd.sh", "/usr/bin/"]
57+
COPY ["zsocket.sh", "/usr/bin/"]
5858
RUN chmod a+x /usr/bin/TSA && \
5959
chmod a+x /usr/bin/TSB && \
60-
chmod a+x /usr/bin/TSC
60+
chmod a+x /usr/bin/TSC && \
61+
chmod a+x /usr/bin/zsocket.sh
6162

6263
ENTRYPOINT ["/usr/bin/docker_init.sh"]

dockers/docker-fpm-frr/frr/supervisord/supervisord.conf.j2

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ stderr_logfile=syslog
3939
dependent_startup=true
4040
dependent_startup_wait_for=rsyslogd:running
4141

42+
[program:zsocket]
43+
command=/usr/bin/zsocket.sh
44+
priority=4
45+
autostart=false
46+
autorestart=false
47+
startsecs=0
48+
stdout_logfile=syslog
49+
stderr_logfile=syslog
50+
dependent_startup=true
51+
dependent_startup_wait_for=zebra:running
52+
4253
[program:staticd]
4354
command=/usr/lib/frr/staticd -A 127.0.0.1
4455
priority=4
@@ -48,7 +59,7 @@ startsecs=0
4859
stdout_logfile=syslog
4960
stderr_logfile=syslog
5061
dependent_startup=true
51-
dependent_startup_wait_for=zebra:running
62+
dependent_startup_wait_for=zsocket:exited
5263

5364
{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
5465
[program:bfdd]
@@ -65,7 +76,7 @@ dependent_startup_wait_for=zebra:running
6576
{% endif %}
6677

6778
[program:bgpd]
68-
command=/usr/bin/bgpd.sh -A 127.0.0.1 -M snmp
79+
command=/usr/lib/frr/bgpd -A 127.0.0.1 -M snmp
6980
priority=5
7081
stopsignal=KILL
7182
autostart=false
@@ -74,7 +85,7 @@ startsecs=0
7485
stdout_logfile=syslog
7586
stderr_logfile=syslog
7687
dependent_startup=true
77-
dependent_startup_wait_for=zebra:running
88+
dependent_startup_wait_for=zsocket:exited
7889

7990
{% if DEVICE_METADATA.localhost.frr_mgmt_framework_config is defined and DEVICE_METADATA.localhost.frr_mgmt_framework_config == "true" %}
8091
[program:ospfd]
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ port=2601
55

66
function help()
77
{
8-
echo "This script aims to ensure zebra is ready to accept connections before starting bgpd"
9-
echo "Usage: $0 [options] [bgpd options]"
8+
echo "This script aims to ensure zebra is ready to accept connections"
9+
echo "Usage: $0 [options]"
1010
echo "Options:"
1111
echo " -a Zebra address"
1212
echo " -o Zebra port"
@@ -23,11 +23,14 @@ while getopts ":a:o:h" opt; do
2323
;;
2424
esac
2525
done
26-
shift $((OPTIND-1))
2726

27+
start=$(date +%s.%N)
2828
timeout 5s bash -c -- "until </dev/tcp/${addr}/${port}; do sleep 0.1;done"
2929
if [ "$?" != "0" ]; then
3030
logger -p error "Error: zebra is not ready to accept connections"
31+
else
32+
timespan=$(awk "BEGIN {print $(date +%s.%N)-$start; exit}")
33+
logger -p info "It took ${timespan} seconds to wait for zebra to be ready to accept connections"
3134
fi
3235

33-
exec /usr/lib/frr/bgpd "$@"
36+
exit 0

0 commit comments

Comments
 (0)