Skip to content

Commit

Permalink
If the IP did not change, do not update it. Also handle empty output …
Browse files Browse the repository at this point in the history
…of host command.
  • Loading branch information
adelton committed Dec 4, 2015
1 parent 00cf3ea commit e50fd48
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions ipa-server-configure-first
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,30 @@ trap exit TERM
trap stop_running EXIT

function update_server_ip_address () {
CURRENT_RECORD=$( host -t A $HOSTNAME_FQDN )
MY_IP=${IPA_SERVER_IP:-$( /sbin/ip addr show | awk '/inet .*global/ { split($2,a,"/"); print a[1]; }' | head -1 )}
if [ "$CURRENT_RECORD" == "$HOSTNAME_FQDN has address $MY_IP" ] ; then
return
fi

kdestroy -A
kinit -k
(
echo "server 127.0.0.1"
echo "update delete $HOSTNAME_FQDN A"
MY_IP=${IPA_SERVER_IP:-$( /sbin/ip addr show | awk '/inet .*global/ { split($2,a,"/"); print a[1]; }' | head -1 )}
echo "update add $HOSTNAME_FQDN 180 A $MY_IP"
echo "send"
echo "quit"
) | nsupdate -g
kdestroy -A

while true ; do
NEW_RECORD=$( host -t A $HOSTNAME_FQDN )
if [ "$?" -eq 0 ] && [ -n "$NEW_RECORD" ] && ! [ "$NEW_RECORD" == "$CURRENT_RECORD" ] ; then
return
fi
sleep 1
done
}

function upgrade_server () {
Expand Down Expand Up @@ -137,13 +150,10 @@ if [ -f /etc/ipa/ca.crt ] ; then
fi
systemctl start-enabled
HOSTNAME_FQDN=$( hostname -f )
while ! host $HOSTNAME_FQDN > /dev/null ; do
sleep 5
while ! host -t A $HOSTNAME_FQDN > /dev/null ; do
sleep 1
done
update_server_ip_address
while ! host $HOSTNAME_FQDN > /dev/null ; do
sleep 5
done
host $HOSTNAME_FQDN
echo "FreeIPA server started."
else
Expand Down

0 comments on commit e50fd48

Please sign in to comment.