From 870d21c436f8ca34f3d865409444e2f4c84a4319 Mon Sep 17 00:00:00 2001 From: Marcus Sorensen Date: Fri, 3 May 2013 14:09:52 -0600 Subject: [PATCH] Summary: Release old DHCP entries Detail: Refresh dnsmasq with updated entries live, no outage BUG-ID: CLOUDSTACK-2299 Submitted-by: Dennis Lawler Signed-off-by: Marcus Sorensen 1367611792 -0600 --- .../systemvm/debian/config/root/edithosts.sh | 28 +++++++++++++------ scripts/network/exdhcp/dnsmasq_edithosts.sh | 19 +++++++++++-- .../systemvmtemplate/postinstall.sh | 2 +- .../systemvmtemplate64/postinstall.sh | 2 +- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/patches/systemvm/debian/config/root/edithosts.sh b/patches/systemvm/debian/config/root/edithosts.sh index 8609da79efd..fb0c34fbd42 100755 --- a/patches/systemvm/debian/config/root/edithosts.sh +++ b/patches/systemvm/debian/config/root/edithosts.sh @@ -19,12 +19,6 @@ # edithosts.sh -- edit the dhcphosts file on the routing domain -# $mac : the mac address -# $ip : the associated ip address -# $host : the hostname -# $4 : default router -# $5 : nameserver on default nic -# $6 : comma separated static routes usage() { printf "Usage: %s: -m -4 -6 -h -d -n -s -u [-N]\n" $(basename $0) >&2 @@ -84,6 +78,9 @@ fi grep "redundant_router=1" /var/cache/cloud/cmdline > /dev/null no_redundant=$? +command -v dhcp_release > /dev/null 2>&1 +no_dhcp_release=$? + wait_for_dnsmasq () { local _pid=$(pidof dnsmasq) for i in 0 1 2 3 4 5 6 7 8 9 10 @@ -97,7 +94,15 @@ wait_for_dnsmasq () { return 1 } -logger -t cloud "edithosts: update $1 $2 $3 to hosts" +if [ $no_dhcp_release -eq 0 ] +then + #release previous dhcp lease if present + logger -t cloud "edithosts: releasing $ipv4" + dhcp_release lo $ipv4 $(grep $ipv4 $DHCP_LEASES | awk '{print $2}') > /dev/null 2>&1 + logger -t cloud "edithosts: released $ipv4" +fi + +logger -t cloud "edithosts: update $mac $ipv4 $ipv6 $host to hosts" [ ! -f $DHCP_HOSTS ] && touch $DHCP_HOSTS [ ! -f $DHCP_OPTS ] && touch $DHCP_OPTS @@ -201,8 +206,13 @@ fi pid=$(pidof dnsmasq) if [ "$pid" != "" ] then - #service dnsmasq restart - kill -HUP $pid + # use SIGHUP to avoid service outage if dhcp_release is available. + if [ $no_dhcp_release -eq 0 ] + then + kill -HUP $pid + else + service dnsmasq restart + fi else if [ $no_redundant -eq 1 ] then diff --git a/scripts/network/exdhcp/dnsmasq_edithosts.sh b/scripts/network/exdhcp/dnsmasq_edithosts.sh index 05285d9accf..7990356edc4 100755 --- a/scripts/network/exdhcp/dnsmasq_edithosts.sh +++ b/scripts/network/exdhcp/dnsmasq_edithosts.sh @@ -35,6 +35,9 @@ wait_for_dnsmasq () { return 1 } +command -v dhcp_release > /dev/null 2>&1 +no_dhcp_release=$? + [ ! -f /etc/dhcphosts.txt ] && touch /etc/dhcphosts.txt [ ! -f /var/lib/misc/dnsmasq.leases ] && touch /var/lib/misc/dnsmasq.leases @@ -44,6 +47,12 @@ sed -i /$3,/d /etc/dhcphosts.txt echo "$1,$2,$3,infinite" >>/etc/dhcphosts.txt +#release previous dhcp lease if present +if [ $no_dhcp_release -eq 0 ] +then + dhcp_release lo $2 $(grep $2 $DHCP_LEASES | awk '{print $2}') > /dev/null 2>&1 +fi + #delete leases to supplied mac and ip addresses sed -i /$1/d /var/lib/misc/dnsmasq.leases sed -i /"$2 "/d /var/lib/misc/dnsmasq.leases @@ -61,9 +70,13 @@ echo "$2 $3" >> /etc/hosts pid=$(pidof dnsmasq) if [ "$pid" != "" ] then - # send SIGHUP to dnsmasq to reload /etc/hosts /etc/dhcphosts.txt - # this will not reload /etc/dnsmasq.conf - kill -s 1 $pid + # use SIGHUP to avoid service outage if dhcp_release is available. + if [ $no_dhcp_release -eq 0 ] + then + kill -HUP $pid + else + service dnsmasq restart + fi else service dnsmasq start wait_for_dnsmasq diff --git a/tools/appliance/definitions/systemvmtemplate/postinstall.sh b/tools/appliance/definitions/systemvmtemplate/postinstall.sh index ae8f1adfb9c..38363d91130 100644 --- a/tools/appliance/definitions/systemvmtemplate/postinstall.sh +++ b/tools/appliance/definitions/systemvmtemplate/postinstall.sh @@ -40,7 +40,7 @@ install_packages() { # haproxy apt-get --no-install-recommends -q -y --force-yes install haproxy # dnsmasq - apt-get --no-install-recommends -q -y --force-yes install dnsmasq + apt-get --no-install-recommends -q -y --force-yes install dnsmasq dnsmasq-utils # nfs client apt-get --no-install-recommends -q -y --force-yes install nfs-common diff --git a/tools/appliance/definitions/systemvmtemplate64/postinstall.sh b/tools/appliance/definitions/systemvmtemplate64/postinstall.sh index ae8f1adfb9c..38363d91130 100644 --- a/tools/appliance/definitions/systemvmtemplate64/postinstall.sh +++ b/tools/appliance/definitions/systemvmtemplate64/postinstall.sh @@ -40,7 +40,7 @@ install_packages() { # haproxy apt-get --no-install-recommends -q -y --force-yes install haproxy # dnsmasq - apt-get --no-install-recommends -q -y --force-yes install dnsmasq + apt-get --no-install-recommends -q -y --force-yes install dnsmasq dnsmasq-utils # nfs client apt-get --no-install-recommends -q -y --force-yes install nfs-common