fix: handled edge network issue when doing provisioning

This commit is contained in:
robcholz
2026-02-09 01:16:20 -05:00
parent ecfce7acf7
commit b433d3ef93
2 changed files with 151 additions and 6 deletions
+46 -2
View File
@@ -1,12 +1,55 @@
#!/bin/bash
set -eux
set -eEux
trap 'echo "[vibebox][error] provisioning failed"; echo "VIBEBOX_PROVISION_FAILED"; systemctl poweroff || true; exit 1' ERR
# Wait for network + DNS before apt-get to avoid early boot flakiness.
wait_for_network() {
echo "[vibebox] waiting for network/DNS readiness"
local deadline=$((SECONDS + 60))
while [ "$SECONDS" -lt "$deadline" ]; do
local has_route=0
if ip -4 route show default >/dev/null 2>&1; then
has_route=1
elif ip -6 route show default >/dev/null 2>&1; then
has_route=1
fi
if [ "$has_route" -eq 1 ]; then
if getent hosts deb.debian.org >/dev/null 2>&1; then
return 0
fi
fi
sleep 1
done
echo "[vibebox][warn] network/DNS still not ready after 60s; continuing" >&2
echo "[vibebox][warn] /etc/resolv.conf:" >&2
cat /etc/resolv.conf >&2 || true
ip -br addr >&2 || true
ip route >&2 || true
ip -6 route >&2 || true
return 0
}
apt_update_with_retries() {
local attempt=1
while [ "$attempt" -le 5 ]; do
if apt-get update; then
return 0
fi
echo "[vibebox][warn] apt-get update failed (attempt ${attempt}/5); retrying..." >&2
attempt=$((attempt + 1))
sleep 2
done
return 1
}
# Don't wait too long for slow mirrors.
echo 'Acquire::http::Timeout "2";' | tee /etc/apt/apt.conf.d/99timeout
echo 'Acquire::https::Timeout "2";' | tee -a /etc/apt/apt.conf.d/99timeout
echo 'Acquire::Retries "2";' | tee -a /etc/apt/apt.conf.d/99timeout
apt-get update
wait_for_network
apt_update_with_retries
apt-get install -y --no-install-recommends \
build-essential \
pkg-config \
@@ -55,4 +98,5 @@ sleep 100 # sleep here so that we don't see the login screen flash up before the
EOF
# Done provisioning, power off the VM
echo "VIBEBOX_PROVISION_OK"
systemctl poweroff