From 1ecbe5682d03fd08da04629274af6a2cf2f61dcb Mon Sep 17 00:00:00 2001 From: Oleksandr Ivantsiv Date: Tue, 13 Aug 2024 15:53:02 -0700 Subject: [PATCH] [Static DNS] Optimize DNS configuration update during interface-config service restart (#19583) #### Why I did it The `resolvconfig` service updates the DNS configuration in the host OS and each running Docker container when a configuration change is detected. The DNS configuration update during the shutdown of the management interface is redundant, as the management interface is going down temporarily and, when it is back online, the DNS configuration will remain the same. The update of the DNS configuration adds a couple of seconds (depending on the CPU) to the interface-config service restart time when the management interface uses a dynamic IP address. This can affect the fast boot. To optimize the flow and execute the service restart faster, the update should be skipped. #### How I did it Do not run DNS configuration update during the shutdown of the management interface. #### How to verify it Measure the execution time of the `service interfaces-config restart` command on the device with the static IP address configuration on the management interface and compare it to the execution time of the same command with the dynamic IP address. The difference should be insignificant. --- .../interfaces/interfaces-config.sh | 21 +++++++++++++++++++ .../resolv-config/update-containers | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/files/image_config/interfaces/interfaces-config.sh b/files/image_config/interfaces/interfaces-config.sh index cb2faea91f31..669d12849f10 100755 --- a/files/image_config/interfaces/interfaces-config.sh +++ b/files/image_config/interfaces/interfaces-config.sh @@ -1,4 +1,5 @@ #!/bin/bash +resolvconf_updates=true function wait_networking_service_done() { local -i _WDOG_CNT="1" @@ -23,6 +24,24 @@ function wait_networking_service_done() { systemctl kill networking 2>&1 } +function resolvconf_updates_disable() { + resolvconf --updates-are-enabled + if [[ $? -ne 0 ]]; then + resolvconf_updates=false + fi + resolvconf --disable-updates +} + +function resolvconf_updates_restore() { + if [[ $resolvconf_updates == true ]]; then + resolvconf --enable-updates + fi +} + +# Do not run DNS configuration update during the shutdowning of the management interface. +# This operation is redundant as there will be an update after the start of the interface. +resolvconf_updates_disable + if [[ $(ifquery --running eth0) ]]; then wait_networking_service_done ifdown --force eth0 @@ -61,6 +80,8 @@ for intf_pid in $(ls -1 /var/run/dhclient*.Ethernet*.pid 2> /dev/null); do done /usr/bin/resolv-config.sh cleanup +# Restore DNS configuration update to the previous state. +resolvconf_updates_restore # Read sysctl conf files again sysctl -p /etc/sysctl.d/90-dhcp6-systcl.conf diff --git a/files/image_config/resolv-config/update-containers b/files/image_config/resolv-config/update-containers index 47d8328a80fe..891fd2ea7462 100755 --- a/files/image_config/resolv-config/update-containers +++ b/files/image_config/resolv-config/update-containers @@ -1,6 +1,11 @@ #!/bin/bash -for container in $(docker ps -a --format=" {{ .ID }}"); do +networking_status=$(systemctl is-active networking.service 2>/dev/null) +if [[ $networking_status != "active" ]]; then + exit 0 +fi + +for container in $(docker ps -q); do docker cp -L /etc/resolv.conf ${container}:/_resolv.conf docker exec -t ${container} bash -c "cat /_resolv.conf > /etc/resolv.conf" docker exec -t ${container} bash -c "rm /_resolv.conf"