From 156cd43a145eab978338ed592b78743c15284c23 Mon Sep 17 00:00:00 2001 From: Deeman Date: Sun, 22 Feb 2026 14:22:22 +0100 Subject: [PATCH] fix(deploy): restore router config to current slot before health check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nginx -t resolves upstream hostnames — if the config points to a stopped slot from a previous failed deploy, the health check fails and the router stays unhealthy indefinitely, blocking all future deploys. Before up -d --wait, write the router config to point to the CURRENT live slot (which is still running) and restart the router. This clears the stale unhealthy state. After the new slot passes health checks, switch the router config to the new slot and reload. Also extracted _write_router_conf() to avoid duplicating the nginx config template. Co-Authored-By: Claude Sonnet 4.6 --- deploy.sh | 58 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/deploy.sh b/deploy.sh index c0bd430..a82777f 100755 --- a/deploy.sh +++ b/deploy.sh @@ -35,9 +35,40 @@ echo "==> Running migrations..." $COMPOSE --profile "$TARGET" run --rm "${TARGET}-app" \ python -m padelnomics.migrations.migrate +# ── Ensure router is healthy before waiting ────────────────── +# nginx -t resolves upstream hostnames — if the config points to a stopped +# slot, the health check fails. Write config for the CURRENT live slot +# (which is still running) so the router stays healthy during --wait. + +_write_router_conf() { + local SLOT="$1" + mkdir -p "$(dirname "$ROUTER_CONF")" + cat > "$ROUTER_CONF" < Resetting router to current slot ($CURRENT)..." + _write_router_conf "$CURRENT" + $COMPOSE restart router +fi + # ── Start & health check ─────────────────────────────────── -# Router config is NOT written yet — router keeps old config so it stays -# healthy while we wait for the new slot to pass its own health check. echo "==> Starting $TARGET (waiting for health check)..." if ! $COMPOSE --profile "$TARGET" up -d --wait; then @@ -62,27 +93,8 @@ fi # ── Write router config and reload (new slot is healthy) ──── -echo "==> Writing router config for $TARGET..." -mkdir -p "$(dirname "$ROUTER_CONF")" -cat > "$ROUTER_CONF" < Reloading router..." +echo "==> Switching router to $TARGET..." +_write_router_conf "$TARGET" $COMPOSE exec router nginx -s reload # ── Cleanup old pre-deploy backups (keep last 3) ─────────────