summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorTim Bielawa <timbielawa@gmail.com>2016-11-01 09:34:27 -0700
committerGitHub <noreply@github.com>2016-11-01 09:34:27 -0700
commitc97858a6bc61251c02d2ca27172ebe87727b776a (patch)
treeb8602a3559c34e5a9cd204c30566b227f8b01b03 /roles
parente977242d747f11a0771f4593a936704802ca3f94 (diff)
parent9f87544c95072d963353dcd2f00fe5d1c20610a3 (diff)
downloadopenshift-c97858a6bc61251c02d2ca27172ebe87727b776a.tar.gz
openshift-c97858a6bc61251c02d2ca27172ebe87727b776a.tar.bz2
openshift-c97858a6bc61251c02d2ca27172ebe87727b776a.tar.xz
openshift-c97858a6bc61251c02d2ca27172ebe87727b776a.zip
Merge pull request #2690 from tbielawa/BZ1374170
Only restart dnsmasq if the DNS servers have changed
Diffstat (limited to 'roles')
-rwxr-xr-xroles/openshift_node_dnsmasq/files/networkmanager/99-origin-dns.sh47
1 files changed, 41 insertions, 6 deletions
diff --git a/roles/openshift_node_dnsmasq/files/networkmanager/99-origin-dns.sh b/roles/openshift_node_dnsmasq/files/networkmanager/99-origin-dns.sh
index 5a187710b..ced0fa663 100755
--- a/roles/openshift_node_dnsmasq/files/networkmanager/99-origin-dns.sh
+++ b/roles/openshift_node_dnsmasq/files/networkmanager/99-origin-dns.sh
@@ -1,4 +1,5 @@
#!/bin/bash -x
+# -*- mode: sh; sh-indentation: 2 -*-
# This NetworkManager dispatcher script replicates the functionality of
# NetworkManager's dns=dnsmasq however, rather than hardcoding the listening
@@ -28,7 +29,16 @@ cd /etc/sysconfig/network-scripts
[ -f ../network ] && . ../network
if [[ $2 =~ ^(up|dhcp4-change)$ ]]; then
- # couldn't find an existing method to determine if the interface owns the
+ # If the origin-upstream-dns config file changed we need to restart
+ NEEDS_RESTART=0
+ UPSTREAM_DNS='/etc/dnsmasq.d/origin-upstream-dns.conf'
+ # We'll regenerate the dnsmasq origin config in a temp file first
+ UPSTREAM_DNS_TMP=`mktemp`
+ UPSTREAM_DNS_TMP_SORTED=`mktemp`
+ CURRENT_UPSTREAM_DNS_SORTED=`mktemp`
+
+ ######################################################################
+ # couldn't find an existing method to determine if the interface owns the
# default route
def_route=$(/sbin/ip route list match 0.0.0.0/0 | awk '{print $3 }')
def_route_int=$(/sbin/ip route get to ${def_route} | awk '{print $3}')
@@ -43,15 +53,37 @@ domain-needed
server=/cluster.local/172.30.0.1
server=/30.172.in-addr.arpa/172.30.0.1
EOF
+ # New config file, must restart
+ NEEDS_RESTART=1
fi
- # zero out our upstream servers list and feed it into dnsmasq
- echo -n > /etc/dnsmasq.d/origin-upstream-dns.conf
+
+ ######################################################################
+ # Generate a new origin dns config file
for ns in ${IP4_NAMESERVERS}; do
if [[ ! -z $ns ]]; then
- echo "server=${ns}" >> /etc/dnsmasq.d/origin-upstream-dns.conf
+ echo "server=${ns}"
fi
- done
- systemctl restart dnsmasq
+ done > $UPSTREAM_DNS_TMP
+
+ # Sort it in case DNS servers arrived in a different order
+ sort $UPSTREAM_DNS_TMP > $UPSTREAM_DNS_TMP_SORTED
+ sort $UPSTREAM_DNS > $CURRENT_UPSTREAM_DNS_SORTED
+
+ # Compare to the current config file (sorted)
+ NEW_DNS_SUM=`md5sum ${UPSTREAM_DNS_TMP_SORTED} | awk '{print $1}'`
+ CURRENT_DNS_SUM=`md5sum ${CURRENT_UPSTREAM_DNS_SORTED} | awk '{print $1}'`
+
+ if [ "${NEW_DNS_SUM}" != "${CURRENT_DNS_SUM}" ]; then
+ # DNS has changed, copy the temp file to the proper location (-Z
+ # sets default selinux context) and set the restart flag
+ cp -Z $UPSTREAM_DNS_TMP $UPSTREAM_DNS
+ NEEDS_RESTART=1
+ fi
+
+ ######################################################################
+ if [ "${NEEDS_RESTART}" -eq "1" ]; then
+ systemctl restart dnsmasq
+ fi
sed -i '0,/^nameserver/ s/^nameserver.*$/nameserver '"${def_route_ip}"'/g' /etc/resolv.conf
@@ -59,4 +91,7 @@ EOF
echo "# nameserver updated by /etc/NetworkManager/dispatcher.d/99-origin-dns.sh" >> /etc/resolv.conf
fi
fi
+
+ # Clean up after yourself
+ rm -f $UPSTREAM_DNS_TMP $UPSTREAM_DNS_TMP_SORTED $CURRENT_UPSTREAM_DNS_SORTED
fi