[DHCP Relay]: Wait for all interfaces to come up before starting DHCP relay (#660)

This commit is contained in:
Joe LeVeque 2017-06-01 18:38:33 -07:00 committed by GitHub
parent 984e6c4bc9
commit e0d22acc9e
2 changed files with 30 additions and 5 deletions

View File

@ -1,16 +1,41 @@
#!/usr/bin/env bash
function wait_until_iface_exists
{
IFACE=$1
echo "Waiting for interface ${IFACE}..."
# Wait for the interface to come up (i.e., 'ip link show' returns 0)
until ip link show $IFACE > /dev/null 2>&1; do
sleep 1
done
echo "Interface ${IFACE} is created"
}
# Create isc-dhcp-relay config file
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isc-dhcp-relay.j2 > /etc/default/isc-dhcp-relay
rm -f /var/run/rsyslogd.pid
supervisorctl start rsyslogd
VLAN_IFACE_NAME=`sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_vlan_interfaces[0]['attachto']"`
# Wait for all interfaces to come up before starting the DHCP relay
# Wait for the VLAN to come up (i.e., 'ip link show' returns 0)
until ip link show $VLAN_IFACE_NAME > /dev/null 2>&1; do
sleep 1
FRONT_PANEL_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
for IFACE in $FRONT_PANEL_IFACES; do
wait_until_iface_exists $IFACE
done
VLAN_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_vlan_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
for IFACE in $VLAN_IFACES; do
wait_until_iface_exists $IFACE
done
PORTCHANNEL_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_portchannel_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
for IFACE in $PORTCHANNEL_IFACES; do
wait_until_iface_exists $IFACE
done
# Start the DHCP relay

View File

@ -1,7 +1,7 @@
[Unit]
Description=DHCP relay container
Requires=docker.service
After=interfaces-config.service
After=swss.service
[Service]
User={{ sonicadmin_user }}