Skip to content

Commit 50a23a9

Browse files
yxiecatiantianlv
authored andcommitted
[router-advertiser] Add templated script to wait for pertinent interfaces to be ready before starting radvd (sonic-net#2558)
1 parent 47088e5 commit 50a23a9

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

dockers/docker-router-advertiser/Dockerfile.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ RUN rm -rf /debs
3030

3131
COPY ["start.sh", "/usr/bin/"]
3232
COPY ["docker-router-advertiser.supervisord.conf", "/etc/supervisor/conf.d/"]
33-
COPY ["radvd.conf.j2", "/usr/share/sonic/templates/"]
33+
COPY ["radvd.conf.j2", "wait_for_intf.sh.j2", "/usr/share/sonic/templates/"]
3434

3535
ENTRYPOINT ["/usr/bin/supervisord"]

dockers/docker-router-advertiser/start.sh

+7
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,12 @@ if [ $NUM_IFACES -eq 0 ]; then
2121
exit 0
2222
fi
2323

24+
# Generate the script that waits for pertinent interfaces to come up and make it executable
25+
sonic-cfggen -d -t /usr/share/sonic/templates/wait_for_intf.sh.j2 > /usr/bin/wait_for_intf.sh
26+
chmod +x /usr/bin/wait_for_intf.sh
27+
28+
# Wait for pertinent interfaces to come up
29+
/usr/bin/wait_for_intf.sh
30+
2431
# Start the router advertiser
2532
supervisorctl start radvd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
3+
STATE_DB_IDX="6"
4+
5+
VLAN_TABLE_PREFIX="VLAN_TABLE"
6+
7+
function wait_until_iface_ready
8+
{
9+
TABLE_PREFIX=$1
10+
IFACE=$2
11+
12+
echo "Waiting until interface $IFACE is ready..."
13+
14+
# Wait for the interface to come up
15+
# (i.e., interface is present in STATE_DB and state is "ok")
16+
while true; do
17+
RESULT=$(redis-cli -n ${STATE_DB_IDX} HGET "${TABLE_PREFIX}|${IFACE}" "state" 2> /dev/null)
18+
if [ x"$RESULT" == x"ok" ]; then
19+
break
20+
fi
21+
22+
sleep 1
23+
done
24+
25+
echo "Interface ${IFACE} is ready!"
26+
}
27+
28+
29+
# Wait for all interfaces to be up and ready
30+
{% for (name, prefix) in VLAN_INTERFACE %}
31+
wait_until_iface_ready ${VLAN_TABLE_PREFIX} {{ name }}
32+
{% endfor %}

rules/docker-router-advertiser.mk

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
DOCKER_ROUTER_ADVERTISER = docker-router-advertiser.gz
44
$(DOCKER_ROUTER_ADVERTISER)_PATH = $(DOCKERS_PATH)/docker-router-advertiser
5+
$(DOCKER_ROUTER_ADVERTISER)_DEPENDS += $(REDIS_TOOLS)
56
$(DOCKER_ROUTER_ADVERTISER)_LOAD_DOCKERS = $(DOCKER_CONFIG_ENGINE)
67
SONIC_DOCKER_IMAGES += $(DOCKER_ROUTER_ADVERTISER)
78
SONIC_INSTALL_DOCKER_IMAGES += $(DOCKER_ROUTER_ADVERTISER)

0 commit comments

Comments
 (0)