Deploy a complete instance with no mods present

Two things stopped a from-scratch deploy finishing in one run.

The mirror reachability probe ran before counting jars, so a fresh instance
with an empty mods directory still failed on an unreachable mirror despite
having nothing to fetch. The probe now runs only when there is at least one jar,
which also means the reverse proxy does not have to be in place yet to build the
initial pack. mc-refresh-restart.sh gets the same treatment: zero jars is a
legitimate state, and the orphan sweep clears the metadata to match.

The probe itself never worked. curl -w '%{http_code}' already prints 000 on a
connection failure, so the trailing "|| echo 000" appended a second one and the
value was 000000, matching neither the unreachable case nor anything else — the
guard silently degraded to a warning. Use "|| true" with a :-000 fallback.
Verified against a refused port and a live host.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
main
Amir Alexander Abdelbaki 2026-08-05 23:38:57 +02:00
parent 908c4ecbb6
commit ae1671b361
2 changed files with 25 additions and 16 deletions

View File

@ -57,13 +57,19 @@ DATASET="$(findmnt -no SOURCE "${SHARE}" 2>/dev/null || true)"
log "Syncing pack metadata against ${MODS_DIR}..." log "Syncing pack metadata against ${MODS_DIR}..."
cd "${PACK_DIR}" cd "${PACK_DIR}"
probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "${BASE_URL}/" || echo 000)"
[ "${probe}" = "000" ] && die "cannot reach ${BASE_URL} — packwiz needs it to hash each mod"
shopt -s nullglob shopt -s nullglob
JARS=("${MODS_DIR}"/*.jar) JARS=("${MODS_DIR}"/*.jar)
shopt -u nullglob shopt -u nullglob
(( ${#JARS[@]} > 0 )) || die "no .jar files in ${MODS_DIR}"
# Zero jars is legitimate — an empty pack, or every mod deliberately removed.
# The orphan sweep below then clears the metadata to match.
if (( ${#JARS[@]} > 0 )); then
probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "${BASE_URL}/" || true)"
probe="${probe:-000}"
[ "${probe}" = "000" ] && die "cannot reach ${BASE_URL} — packwiz needs it to hash each mod"
else
log "WARNING: no .jar files in ${MODS_DIR} — pack will end up empty"
fi
added=0; updated=0; unchanged=0; FAILED=() added=0; updated=0; unchanged=0; FAILED=()
declare -A SEEN=() declare -A SEEN=()
@ -150,7 +156,8 @@ if [ -n "${PACK_URL}" ]; then
fi fi
# index.toml is fetched as a separate request and cached separately. # index.toml is fetched as a separate request and cached separately.
idx="$(curl -fsS --max-time 10 -o /dev/null -w '%{http_code}' "${PACK_URL}/index.toml" || echo 000)" idx="$(curl -fsS --max-time 10 -o /dev/null -w '%{http_code}' "${PACK_URL}/index.toml" || true)"
idx="${idx:-000}"
[ "${idx}" = "200" ] || die "${PACK_URL}/index.toml returned HTTP ${idx} — clients cannot resolve the pack" [ "${idx}" = "200" ] || die "${PACK_URL}/index.toml returned HTTP ${idx} — clients cannot resolve the pack"
fi fi

View File

@ -234,16 +234,6 @@ if [ -n "$MODSDIR" ]; then
grep -q 'url' <<<"$("$PACKWIZ" --help 2>&1 || true)" \ grep -q 'url' <<<"$("$PACKWIZ" --help 2>&1 || true)" \
|| die "this packwiz build has no 'url' subcommand — cannot add mods by URL" || die "this packwiz build has no 'url' subcommand — cannot add mods by URL"
# packwiz downloads each URL to hash it, so a mirror that isn't up yet
# produces a pile of confusing per-mod failures. Check once, up front.
info "checking mirror at $BASEURL"
probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "$BASEURL/" || echo 000)"
case "$probe" in
2*|3*|40[34]) ;; # a listing may legitimately be forbidden
000) die "cannot reach $BASEURL — start the mirror before running this" ;;
*) warn "$BASEURL/ returned HTTP $probe; continuing, individual mods may fail" ;;
esac
shopt -s nullglob shopt -s nullglob
jars=("$MODSDIR"/*.jar) jars=("$MODSDIR"/*.jar)
shopt -u nullglob shopt -u nullglob
@ -251,9 +241,21 @@ if [ -n "$MODSDIR" ]; then
failed=() failed=()
if [ "${#jars[@]}" -eq 0 ]; then if [ "${#jars[@]}" -eq 0 ]; then
# An empty pack is a valid starting point: drop jars in later and run # An empty pack is a valid starting point: drop jars in later and run
# mc-refresh-restart.sh to register them. # mc-refresh-restart.sh to register them. Nothing needs fetching, so the
# mirror does not have to be reachable yet either.
warn "no .jar files in $MODSDIR yet — creating an empty pack" warn "no .jar files in $MODSDIR yet — creating an empty pack"
else else
# packwiz downloads each URL to hash it, so a mirror that isn't up yet
# produces a pile of confusing per-mod failures. Check once, up front.
info "checking mirror at $BASEURL"
probe="$(curl -so /dev/null -w '%{http_code}' --max-time 10 "$BASEURL/" || true)"
probe="${probe:-000}"
case "$probe" in
2*|3*|40[34]) ;; # a listing may legitimately be forbidden
000) die "cannot reach $BASEURL — the pack server or proxy is not up yet" ;;
*) warn "$BASEURL/ returned HTTP $probe; continuing, individual mods may fail" ;;
esac
info "adding ${#jars[@]} mods from the mirror" info "adding ${#jars[@]} mods from the mirror"
for jar in "${jars[@]}"; do for jar in "${jars[@]}"; do
file="$(basename "$jar")" file="$(basename "$jar")"