mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-10-26 08:42:29 +01:00 
			
		
		
		
	Summary: Release old DHCP entries
Detail: Refresh dnsmasq with updated entries live, no outage BUG-ID: CLOUDSTACK-2299 Submitted-by: Dennis Lawler <dlawler@gmail.com> Signed-off-by: Marcus Sorensen <marcus@betterservers.com> 1367611792 -0600
This commit is contained in:
		
							parent
							
								
									a3a5c13427
								
							
						
					
					
						commit
						870d21c436
					
				| @ -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 | ||||
|   # 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 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
| @ -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 | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user