Summary: Release old DHCP entries

Detail: Refresh dnsmasq with updated entries live, no outage

BUG-ID: CLOUDSTACK-2299
Submitted-by: Dennis Lawler <[email protected]>
Signed-off-by: Marcus Sorensen <[email protected]> 1367611792 -0600


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/870d21c4
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/870d21c4
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/870d21c4

Branch: refs/heads/ui-cisco-asa1000v-support
Commit: 870d21c436f8ca34f3d865409444e2f4c84a4319
Parents: a3a5c13
Author: Marcus Sorensen <[email protected]>
Authored: Fri May 3 14:09:52 2013 -0600
Committer: Marcus Sorensen <[email protected]>
Committed: Fri May 3 14:09:52 2013 -0600

----------------------------------------------------------------------
 patches/systemvm/debian/config/root/edithosts.sh   |   28 ++++++++++-----
 scripts/network/exdhcp/dnsmasq_edithosts.sh        |   19 ++++++++--
 .../definitions/systemvmtemplate/postinstall.sh    |    2 +-
 .../definitions/systemvmtemplate64/postinstall.sh  |    2 +-
 4 files changed, 37 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/870d21c4/patches/systemvm/debian/config/root/edithosts.sh
----------------------------------------------------------------------
diff --git a/patches/systemvm/debian/config/root/edithosts.sh 
b/patches/systemvm/debian/config/root/edithosts.sh
index 8609da7..fb0c34f 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 <MAC address> -4 <IPv4 address> -6 <IPv6 address> -h 
<hostname> -d <default router> -n <name server address> -s <Routes> -u <DUID> 
[-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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/870d21c4/scripts/network/exdhcp/dnsmasq_edithosts.sh
----------------------------------------------------------------------
diff --git a/scripts/network/exdhcp/dnsmasq_edithosts.sh 
b/scripts/network/exdhcp/dnsmasq_edithosts.sh
index 05285d9..7990356 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

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/870d21c4/tools/appliance/definitions/systemvmtemplate/postinstall.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvmtemplate/postinstall.sh 
b/tools/appliance/definitions/systemvmtemplate/postinstall.sh
index ae8f1ad..38363d9 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
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/870d21c4/tools/appliance/definitions/systemvmtemplate64/postinstall.sh
----------------------------------------------------------------------
diff --git a/tools/appliance/definitions/systemvmtemplate64/postinstall.sh 
b/tools/appliance/definitions/systemvmtemplate64/postinstall.sh
index ae8f1ad..38363d9 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
 

Reply via email to