CLOUDSTACK-5986: Make dnsmasq handle dnsmasq.leases when dhcp_release is available

The original issue has been exposed due to CloudStack VR would modify the
dnsmasq.leases, thus make it unsync with dnsmasq's memory lease.

Make the modification to let dnsmasq handle the lease file if dhcp_release is
available.
This commit is contained in:
Sheng Yang 2014-01-29 16:15:24 -08:00
parent b38c033d5c
commit 121d88743a
2 changed files with 35 additions and 28 deletions

View File

@ -750,6 +750,16 @@ setup_dnsmasq() {
sed -i -e "/^dhcp-client-update/d" /etc/dnsmasq.conf sed -i -e "/^dhcp-client-update/d" /etc/dnsmasq.conf
echo 'dhcp-client-update' >> /etc/dnsmasq.conf echo 'dhcp-client-update' >> /etc/dnsmasq.conf
fi fi
command -v dhcp_release > /dev/null 2>&1
no_dhcp_release=$?
if [ $no_dhcp_release -eq 0 -a -z "$ETH0_IP6" ]
then
echo 1 > /var/cache/cloud/dnsmasq_managed_lease
sed -i -e "/^leasefile-ro/d" /etc/dnsmasq.conf
else
echo 0 > /var/cache/cloud/dnsmasq_managed_lease
fi
} }
setup_sshd(){ setup_sshd(){

View File

@ -80,8 +80,7 @@ fi
grep "redundant_router=1" /var/cache/cloud/cmdline > /dev/null grep "redundant_router=1" /var/cache/cloud/cmdline > /dev/null
no_redundant=$? no_redundant=$?
command -v dhcp_release > /dev/null 2>&1 dnsmasq_managed_lease=`cat /var/cache/cloud/dnsmasq_managed_lease`
no_dhcp_release=$?
wait_for_dnsmasq () { wait_for_dnsmasq () {
local _pid=$(pidof dnsmasq) local _pid=$(pidof dnsmasq)
@ -96,12 +95,7 @@ wait_for_dnsmasq () {
return 1 return 1
} }
if [ $ipv6 ] if [ $dnsmasq_managed_lease ]
then
no_dhcp_release=1
fi
if [ $no_dhcp_release -eq 0 ]
then then
#release previous dhcp lease if present #release previous dhcp lease if present
logger -t cloud "edithosts: releasing $ipv4" logger -t cloud "edithosts: releasing $ipv4"
@ -145,27 +139,30 @@ then
fi fi
fi fi
#delete leases to supplied mac and ip addresses if [ $dnsmasq_managed_lease -eq 0 ]
if [ $ipv4 ]
then then
sed -i /$mac/d $DHCP_LEASES #delete leases to supplied mac and ip addresses
sed -i /"$ipv4 "/d $DHCP_LEASES if [ $ipv4 ]
fi then
if [ $ipv6 ] sed -i /$mac/d $DHCP_LEASES
then sed -i /"$ipv4 "/d $DHCP_LEASES
sed -i /$duid/d $DHCP_LEASES fi
sed -i /"$ipv6 "/d $DHCP_LEASES if [ $ipv6 ]
fi then
sed -i /"$host "/d $DHCP_LEASES sed -i /$duid/d $DHCP_LEASES
sed -i /"$ipv6 "/d $DHCP_LEASES
fi
sed -i /"$host "/d $DHCP_LEASES
#put in the new entry #put in the new entry
if [ $ipv4 ] if [ $ipv4 ]
then then
echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES echo "0 $mac $ipv4 $host *" >> $DHCP_LEASES
fi fi
if [ $ipv6 ] if [ $ipv6 ]
then then
echo "0 $duid $ipv6 $host *" >> $DHCP_LEASES echo "0 $duid $ipv6 $host *" >> $DHCP_LEASES
fi
fi fi
#edit hosts file as well #edit hosts file as well
@ -215,7 +212,7 @@ pid=$(pidof dnsmasq)
if [ "$pid" != "" ] if [ "$pid" != "" ]
then then
# use SIGHUP to avoid service outage if dhcp_release is available. # use SIGHUP to avoid service outage if dhcp_release is available.
if [ $no_dhcp_release -eq 0 ] if [ $dnsmasq_managed_lease ]
then then
kill -HUP $pid kill -HUP $pid
else else