Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipa-server-configure-first: add timeout to the host resolution #630

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 26 additions & 9 deletions ipa-server-configure-first
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,32 @@ function update_server_ip_address () {
done
}

function wait_for_dns () {
local TIMEOUT="$1"
local WAIT_UNTIL="$((SECONDS + TIMEOUT))"
while ! host -t A $HOSTNAME > /dev/null ; do
if [[ "$SECONDS" -lt "$WAIT_UNTIL" ]]; then
sleep 1
continue
fi
return 1
done
return 0
}

if [ "$1" == update-self-ip-address ] ; then
exec >> /var/log/ipa-server-run.log 2>&1
echo "$(date) $0 $@"

if systemctl is-active -q named named-pkcs11 || [ -f /run/ipa/ipa-server-ip ] ; then
# Wait until DNS is up and running and resolving
while ! host -t A $HOSTNAME > /dev/null ; do
sleep 1
done
update_server_ip_address
host $HOSTNAME
if wait_for_dns 60; then
update_server_ip_address
host $HOSTNAME
else
echo "Unable to resolve \"${HOSTNAME}\". Is --dns=127.0.0.1 set for the container?" >&2
exit 2
fi
else
echo "FreeIPA server does not run DNS server, skipping update-self-ip-address."
fi
Expand Down Expand Up @@ -211,10 +226,12 @@ else

if systemctl is-active -q named named-pkcs11 || [ -f /run/ipa/ipa-server-ip ] ; then
cp -f /etc/resolv.conf /data/etc/resolv.conf.ipa
while ! host -t A $HOSTNAME > /dev/null ; do
sleep 1
done
update_server_ip_address
if wait_for_dns 180; then
update_server_ip_address
else
echo "Unable to resolve \"${HOSTNAME}\". Is --dns=127.0.0.1 set for the container?" >&2
exit 2
fi
else
echo "FreeIPA server does not run DNS server, skipping update-self-ip-address."
fi
Expand Down