Skip to content

Commit 70bb92c

Browse files
Implement wait_for_internal_ip function to ensure dappmanager publishes INTERNAL_IP before proceeding
1 parent adc867e commit 70bb92c

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

scripts/dappnode_install.sh

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,50 @@ check_prereqs() {
7474
fi
7575
}
7676

77+
# Wait until dappmanager publishes INTERNAL_IP via its local HTTP endpoint.
78+
# Runs the curl inside the provided container and exits with error on timeout.
79+
# Usage: wait_for_internal_ip <container_name> [timeout_seconds] [initial_sleep_seconds]
80+
wait_for_internal_ip() {
81+
local container_name="$1"
82+
local timeout_seconds="${2:-120}"
83+
local initial_sleep_seconds="${3:-10}"
84+
local url="http://127.0.0.1/global-envs/INTERNAL_IP"
85+
86+
echo "Waiting for dappmanager to publish INTERNAL_IP..."
87+
sleep "$initial_sleep_seconds"
88+
89+
local start_seconds http_code value result
90+
start_seconds=$SECONDS
91+
http_code=""
92+
value=""
93+
94+
while true; do
95+
if (( SECONDS - start_seconds >= timeout_seconds )); then
96+
die "Timed out after ${timeout_seconds}s waiting for INTERNAL_IP from dappmanager (expected HTTP 200 with a non-empty value). Last seen: code=${http_code:-?}, value=${value:-<empty>}"
97+
fi
98+
99+
# Must be executed inside the dappmanager container
100+
# Wait until we get HTTP 200 and a non-empty value back.
101+
# Return format is:
102+
# <body>\n<http_code>
103+
# Parse in bash (not inside container sh) to avoid shell portability issues.
104+
result="$(
105+
docker exec -i "$container_name" sh -lc "curl -sS -w '\n%{http_code}' '$url' 2>/dev/null || true" 2>/dev/null || true
106+
)"
107+
108+
http_code="$(printf '%s\n' "$result" | tail -n 1 | tr -d '\r')"
109+
value="$(printf '%s\n' "$result" | head -n 1 | tr -d '\r' | xargs)"
110+
111+
if [[ "$http_code" == "200" && -n "$value" && "$value" != "null" ]]; then
112+
echo "INTERNAL_IP is ready: $value"
113+
return 0
114+
fi
115+
116+
echo "INTERNAL_IP not ready yet (code=${http_code:-?}). Retrying..."
117+
sleep 2
118+
done
119+
}
120+
77121
# Build docker compose "-f <file>" args from downloaded compose files.
78122
# This avoids depending on alias expansion or profile-generated strings.
79123
build_dncore_compose_args() {
@@ -836,7 +880,7 @@ main() {
836880

837881
echo ""
838882
echo "Waiting for VPN initialization..."
839-
sleep 30
883+
wait_for_internal_ip "DAppNodeCore-dappmanager.dnp.dappnode.eth" 120 10
840884

841885
echo ""
842886
echo "##############################################"

0 commit comments

Comments
 (0)