fix: replace getent DNS check with curl in first-login.sh
getent blocks indefinitely when the nameserver is unreachable (QEMU 10.0.2.3, or any network where DNS responds slowly). Replace with curl --connect-timeout 3 which has a hard 3s per-attempt timeout and is independent of the NSS stack.
This commit is contained in:
@@ -11,12 +11,14 @@ exec > >(tee -a "$LOG") 2>&1
|
|||||||
|
|
||||||
echo "==> [$(date)] first-login setup starting"
|
echo "==> [$(date)] first-login setup starting"
|
||||||
|
|
||||||
# Need network. Wait up to 60s for default route + DNS.
|
# Need network. Wait up to 60s for HTTPS connectivity.
|
||||||
for i in $(seq 1 30); do
|
# Use curl with a short timeout rather than getent — getent blocks indefinitely
|
||||||
getent hosts github.com >/dev/null 2>&1 && break
|
# when the DNS nameserver is unreachable (e.g. QEMU's 10.0.2.3 not responding).
|
||||||
sleep 2
|
for i in $(seq 1 20); do
|
||||||
|
curl -fsSL --max-time 3 --connect-timeout 3 -o /dev/null https://api.github.com 2>/dev/null && break
|
||||||
|
sleep 3
|
||||||
done
|
done
|
||||||
if ! getent hosts github.com >/dev/null 2>&1; then
|
if ! curl -fsSL --max-time 3 --connect-timeout 3 -o /dev/null https://api.github.com 2>/dev/null; then
|
||||||
echo "!! no network; aborting first-login setup (will retry next login)"
|
echo "!! no network; aborting first-login setup (will retry next login)"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user