Skip to content

Commit e0d22ac

Browse files
authored
[DHCP Relay]: Wait for all interfaces to come up before starting DHCP relay (#660)
1 parent 984e6c4 commit e0d22ac

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

dockers/docker-dhcp-relay/start.sh

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,41 @@
11
#!/usr/bin/env bash
22

3+
function wait_until_iface_exists
4+
{
5+
IFACE=$1
6+
7+
echo "Waiting for interface ${IFACE}..."
8+
9+
# Wait for the interface to come up (i.e., 'ip link show' returns 0)
10+
until ip link show $IFACE > /dev/null 2>&1; do
11+
sleep 1
12+
done
13+
14+
echo "Interface ${IFACE} is created"
15+
}
16+
17+
# Create isc-dhcp-relay config file
318
sonic-cfggen -m /etc/sonic/minigraph.xml -t /usr/share/sonic/templates/isc-dhcp-relay.j2 > /etc/default/isc-dhcp-relay
419

520
rm -f /var/run/rsyslogd.pid
621

722
supervisorctl start rsyslogd
823

9-
VLAN_IFACE_NAME=`sonic-cfggen -m /etc/sonic/minigraph.xml -v "minigraph_vlan_interfaces[0]['attachto']"`
24+
# Wait for all interfaces to come up before starting the DHCP relay
25+
26+
FRONT_PANEL_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
27+
for IFACE in $FRONT_PANEL_IFACES; do
28+
wait_until_iface_exists $IFACE
29+
done
30+
31+
VLAN_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_vlan_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
32+
for IFACE in $VLAN_IFACES; do
33+
wait_until_iface_exists $IFACE
34+
done
1035

11-
# Wait for the VLAN to come up (i.e., 'ip link show' returns 0)
12-
until ip link show $VLAN_IFACE_NAME > /dev/null 2>&1; do
13-
sleep 1
36+
PORTCHANNEL_IFACES=$(sonic-cfggen -m /etc/sonic/minigraph.xml --var-json "minigraph_portchannel_interfaces" | grep "\"attachto\":" | sed 's/^\s*"attachto":\s"\(.*\)".*$/\1/')
37+
for IFACE in $PORTCHANNEL_IFACES; do
38+
wait_until_iface_exists $IFACE
1439
done
1540

1641
# Start the DHCP relay

files/build_templates/dhcp_relay.service.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[Unit]
22
Description=DHCP relay container
33
Requires=docker.service
4-
After=interfaces-config.service
4+
After=swss.service
55

66
[Service]
77
User={{ sonicadmin_user }}

0 commit comments

Comments
 (0)