diff --git a/deploy.sh b/deploy.sh index 24268a5..6b8589b 100755 --- a/deploy.sh +++ b/deploy.sh @@ -84,6 +84,24 @@ verify() { fi } +# Recreating the app container can give it a NEW docker network IP. Nginx Proxy Manager caches the app's +# upstream IP at config-load, so it would keep hitting the OLD IP ("Connection refused" → site down) until +# it re-resolves. Reload NPM's nginx so it picks up the current IP. Non-fatal: warn (don't fail) if NPM +# isn't found — some environments run a different reverse proxy. +reload_proxy() { + local npm + npm="$(docker ps --format '{{.Names}}' | grep -iE 'nginx.?proxy.?manager.*app' | head -n1 || true)" + if [ -n "$npm" ] && docker exec "$npm" nginx -t >/dev/null 2>&1; then + if docker exec "$npm" nginx -s reload >/dev/null 2>&1; then + ok "Reloaded $npm (re-resolved app upstream IP)." + else + warn "Could not reload $npm — if the site 502s, run: docker exec $npm nginx -s reload" + fi + else + warn "Reverse proxy (NPM) not auto-detected; if the site fails after deploy, reload it so it re-resolves the app IP." + fi +} + # --- rollback mode --- if [ "$ROLLBACK" -eq 1 ]; then latest="$(ls -1t "$BK_DIR"/*.tgz 2>/dev/null | head -n1 || true)" @@ -91,7 +109,7 @@ if [ "$ROLLBACK" -eq 1 ]; then log "Rolling back from: $latest" snapshot # snapshot the (broken) current state first tar -xzf "$latest" -C "$APP_DIR" - rebuild; verify + rebuild; verify; reload_proxy ok "Rolled back to $latest" exit 0 fi @@ -106,5 +124,6 @@ if [ "$DO_PULL" -eq 1 ]; then fi rebuild verify +reload_proxy ok "Deploy complete. Backups kept: $KEEP_BACKUPS (in $BK_DIR)." echo " Rollback with: ./deploy.sh --rollback"