sonic-buildimage/dockers/docker-dhcp-relay/wait_for_intf.sh.j2
Saikrishna Arcot 52e9909373 docker-dhcp-relay: Fix waiting for interfaces to get set up (#9034)
Fix the check used to wait for interfaces to come up. The group name in
the supervisor config files has changed from isc-dhcp-relay to
dhcp-relay.

Also, in the wait script, wait 10 additional seconds after the vlans,
port channels, and any interfaces are up. This is because dhcrelay
listens on all interfaces (in addition to port channels and vlans), and
to ensure that it stays in a clean state during runtime, wait some extra
time to make sure that those interfaces are created as well.

Signed-off-by: Saikrishna Arcot <sarcot@microsoft.com>
2021-11-14 15:15:34 -08:00

46 lines
1.2 KiB
Django/Jinja

#!/usr/bin/env bash
function wait_until_iface_ready
{
IFACE_NAME=$1
IFACE_CIDR=$2
echo "Waiting until interface ${IFACE_NAME} 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=$(sonic-db-cli STATE_DB HGET "INTERFACE_TABLE|${IFACE_NAME}|${IFACE_CIDR}" "state" 2> /dev/null)
if [ x"$RESULT" == x"ok" ]; then
break
fi
sleep 1
done
echo "Interface ${IFACE_NAME} is ready!"
}
# Wait for all interfaces with IPv4 addresses to be up and ready
{% for (name, prefix) in INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
wait_until_iface_ready {{ name }} {{ prefix }}
{% endif %}
{% endfor %}
{% for (name, prefix) in VLAN_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
wait_until_iface_ready {{ name }} {{ prefix }}
{% endif %}
{% endfor %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE|pfx_filter %}
{% if prefix | ipv4 %}
wait_until_iface_ready {{ name }} {{ prefix }}
{% endif %}
{% endfor %}
# Wait 10 seconds for the rest of interfaces to get added/populated.
# dhcrelay listens on each of the interfaces (in addition to the port
# channels and vlan interfaces)
sleep 10