From b48037090ee56cf1362cf97085c9d9a8c27acc54 Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Sat, 2 Mar 2019 15:45:43 -0800 Subject: [PATCH] [router-advertiser] Add templated script to wait for pertinent interfaces to be ready before starting radvd (#2558) --- .../docker-router-advertiser/Dockerfile.j2 | 2 +- dockers/docker-router-advertiser/start.sh | 7 ++++ .../wait_for_intf.sh.j2 | 32 +++++++++++++++++++ rules/docker-router-advertiser.mk | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 dockers/docker-router-advertiser/wait_for_intf.sh.j2 diff --git a/dockers/docker-router-advertiser/Dockerfile.j2 b/dockers/docker-router-advertiser/Dockerfile.j2 index 40589f2e6e..9034724abe 100644 --- a/dockers/docker-router-advertiser/Dockerfile.j2 +++ b/dockers/docker-router-advertiser/Dockerfile.j2 @@ -30,6 +30,6 @@ RUN rm -rf /debs COPY ["start.sh", "/usr/bin/"] COPY ["docker-router-advertiser.supervisord.conf", "/etc/supervisor/conf.d/"] -COPY ["radvd.conf.j2", "/usr/share/sonic/templates/"] +COPY ["radvd.conf.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"] ENTRYPOINT ["/usr/bin/supervisord"] diff --git a/dockers/docker-router-advertiser/start.sh b/dockers/docker-router-advertiser/start.sh index 159006a176..8d5f73a8bc 100755 --- a/dockers/docker-router-advertiser/start.sh +++ b/dockers/docker-router-advertiser/start.sh @@ -21,5 +21,12 @@ if [ $NUM_IFACES -eq 0 ]; then exit 0 fi +# Generate the script that waits for pertinent interfaces to come up and make it executable +sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh +chmod +x /usr/bin/wait_for_intf.sh + +# Wait for pertinent interfaces to come up +/usr/bin/wait_for_intf.sh + # Start the router advertiser supervisorctl start radvd diff --git a/dockers/docker-router-advertiser/wait_for_intf.sh.j2 b/dockers/docker-router-advertiser/wait_for_intf.sh.j2 new file mode 100644 index 0000000000..856c47678f --- /dev/null +++ b/dockers/docker-router-advertiser/wait_for_intf.sh.j2 @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +STATE_DB_IDX="6" + +VLAN_TABLE_PREFIX="VLAN_TABLE" + +function wait_until_iface_ready +{ + TABLE_PREFIX=$1 + IFACE=$2 + + echo "Waiting until interface $IFACE is ready..." + + # Wait for the interface to come up + # (i.e., interface is present in STATE_DB and state is "ok") + while true; do + RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null) + if [ x"$RESULT" == x"ok" ]; then + break + fi + + sleep 1 + done + + echo "Interface ${IFACE} is ready!" +} + + +# Wait for all interfaces to be up and ready +{% for (name, prefix) in VLAN_INTERFACE %} +wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }} +{% endfor %} diff --git a/rules/docker-router-advertiser.mk b/rules/docker-router-advertiser.mk index 90c7b6fa89..b4b20b768d 100644 --- a/rules/docker-router-advertiser.mk +++ b/rules/docker-router-advertiser.mk @@ -2,6 +2,7 @@ DOCKER_ROUTER_ADVERTISER = docker-router-advertiser.gz $(DOCKER_ROUTER_ADVERTISER)_PATH = $(DOCKERS_PATH)/docker-router-advertiser +$(DOCKER_ROUTER_ADVERTISER)_DEPENDS += $(REDIS_TOOLS) $(DOCKER_ROUTER_ADVERTISER)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE_STRETCH) SONIC_DOCKER_IMAGES += $(DOCKER_ROUTER_ADVERTISER) SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_ROUTER_ADVERTISER)