Skip to content

Commit 8a863ab

Browse files
Enhance wait_for_internal_ip function to check for HOSTNAME alongside INTERNAL_IP and improve error messaging; add wait for maindb.json file existence in macOS non-server patch function
1 parent abfef52 commit 8a863ab

1 file changed

Lines changed: 35 additions & 19 deletions

File tree

scripts/dappnode_install.sh

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,49 @@ wait_for_internal_ip() {
8181
local container_name="$1"
8282
local timeout_seconds="${2:-120}"
8383
local initial_sleep_seconds="${3:-10}"
84-
local url="http://127.0.0.1/global-envs/INTERNAL_IP"
84+
local internal_ip_url="http://127.0.0.1/global-envs/INTERNAL_IP"
85+
local hostname_url="http://127.0.0.1/global-envs/HOSTNAME"
8586

86-
echo "Waiting for dappmanager to publish INTERNAL_IP..."
87+
echo "Waiting for dappmanager to publish INTERNAL_IP and HOSTNAME..."
8788
sleep "$initial_sleep_seconds"
8889

89-
local start_seconds http_code value result
90+
local start_seconds internal_http_code internal_value internal_result
91+
local hostname_http_code hostname_value hostname_result
9092
start_seconds=$SECONDS
91-
http_code=""
92-
value=""
93+
internal_http_code=""
94+
internal_value=""
95+
hostname_http_code=""
96+
hostname_value=""
9397

9498
while true; do
9599
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>}"
100+
die "Timed out after ${timeout_seconds}s waiting for INTERNAL_IP and HOSTNAME from dappmanager (expected HTTP 200 with non-empty values). Last seen: INTERNAL_IP code=${internal_http_code:-?} value=${internal_value:-<empty>}; HOSTNAME code=${hostname_http_code:-?} value=${hostname_value:-<empty>}"
97101
fi
98102

99-
# Must be executed inside the dappmanager container
100-
# Wait until we get HTTP 200 and a non-empty value back.
103+
# Must be executed inside the dappmanager container.
101104
# Return format is:
102105
# <body>\n<http_code>
103106
# 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
107+
108+
internal_result="$(
109+
docker exec -i "$container_name" sh -lc "curl -sS -w '\n%{http_code}' '$internal_ip_url' 2>/dev/null || true" 2>/dev/null || true
106110
)"
111+
internal_http_code="$(printf '%s\n' "$internal_result" | tail -n 1 | tr -d '\r')"
112+
internal_value="$(printf '%s\n' "$internal_result" | head -n 1 | tr -d '\r' | xargs)"
107113

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)"
114+
hostname_result="$(
115+
docker exec -i "$container_name" sh -lc "curl -sS -w '\n%{http_code}' '$hostname_url' 2>/dev/null || true" 2>/dev/null || true
116+
)"
117+
hostname_http_code="$(printf '%s\n' "$hostname_result" | tail -n 1 | tr -d '\r')"
118+
hostname_value="$(printf '%s\n' "$hostname_result" | head -n 1 | tr -d '\r' | xargs)"
110119

111-
if [[ "$http_code" == "200" && -n "$value" && "$value" != "null" ]]; then
112-
echo "INTERNAL_IP is ready: $value"
120+
if [[ "$internal_http_code" == "200" && -n "$internal_value" && "$internal_value" != "null" && "$hostname_http_code" == "200" && -n "$hostname_value" && "$hostname_value" != "null" ]]; then
121+
echo "INTERNAL_IP is ready: $internal_value"
122+
echo "HOSTNAME is ready: $hostname_value"
113123
return 0
114124
fi
115125

116-
echo "INTERNAL_IP not ready yet (code=${http_code:-?}). Retrying..."
126+
echo "INTERNAL_IP/HOSTNAME not ready yet (INTERNAL_IP code=${internal_http_code:-?}, HOSTNAME code=${hostname_http_code:-?}). Retrying..."
117127
sleep 2
118128
done
119129
}
@@ -373,10 +383,16 @@ patch_maindb_for_macos_nonserver() {
373383
fi
374384

375385
local maindb_file="${DAPPNODE_CORE_DIR}/maindb.json"
376-
if [[ ! -f "$maindb_file" ]]; then
377-
warn "macOS non-server: maindb.json not found at ${maindb_file}; skipping"
378-
return 0
379-
fi
386+
# Wait (up to 2 minutes) for maindb.json to exist.
387+
local start_seconds
388+
start_seconds=$SECONDS
389+
while [[ ! -f "$maindb_file" ]]; do
390+
if (( SECONDS - start_seconds >= 120 )); then
391+
warn "macOS non-server: maindb.json not found at ${maindb_file} after 120s; skipping"
392+
return 0
393+
fi
394+
sleep 2
395+
done
380396

381397
log "macOS non-server: patching maindb.json to use remote IPFS"
382398

0 commit comments

Comments
 (0)