Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DHCP relay]: Wait for all interfaces to be assigned IPv4 addresses before starting relay agent(s) #1173

Merged
merged 2 commits into from
Nov 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion dockers/docker-dhcp-relay/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ rm -f /var/run/rsyslogd.pid
# Start rsyslog
supervisorctl start rsyslogd

# Wait for all interfaces to come up before starting the DHCP relay agent(s)
# Wait for all interfaces to come up and be assigned IPv4 addresses before
# starting the DHCP relay agent(s). If an interface the relay should listen
# on is down, the relay agent will not start. If an interface the relay should
# listen on is up but does not have an IP address assigned when the relay
# agent starts, it will not listen or send on that interface for the lifetime
# of the process.
/usr/bin/wait_for_intf.sh

# Start the DHCP relay agent(s)
Expand Down
31 changes: 23 additions & 8 deletions dockers/docker-dhcp-relay/wait_for_intf.sh.j2
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
#!/usr/bin/env bash

function wait_until_iface_exists
function wait_until_iface_ready
{
IFACE=$1

echo "Waiting for interface ${IFACE}..."
echo "Waiting until interface $IFACE is up..."

# Wait for the interface to come up (i.e., 'ip link show' returns 0)
until ip link show $IFACE > /dev/null 2>&1; do
until ip link show dev $IFACE up > /dev/null 2>&1; do
sleep 1
done

echo "Interface ${IFACE} is created"
echo "Interface $IFACE is up"

echo "Waiting until interface $IFACE has an IPv4 address..."

# Wait until the interface gets assigned an IPv4 address
while true; do
IP=$(ip -4 addr show dev $IFACE | grep "inet " | awk '{ print $2 }' | cut -d '/' -f1)

if [ -n "$IP" ]; then
break
fi

sleep 1
done

echo "Interface $IFACE is configured with IP $IP"
}


# Wait for all interfaces to come up before starting the DHCP relay
# Wait for all interfaces to come up and have IPv4 addresses assigned
{% for (name, prefix) in INTERFACE %}
wait_until_iface_exists {{ name }}
wait_until_iface_ready {{ name }}
{% endfor %}
{% for (name, prefix) in VLAN_INTERFACE %}
wait_until_iface_exists {{ name }}
wait_until_iface_ready {{ name }}
{% endfor %}
{% for (name, prefix) in PORTCHANNEL_INTERFACE %}
wait_until_iface_exists {{ name }}
wait_until_iface_ready {{ name }}
{% endfor %}