fix(deploy): reload NPM after deploy so it re-resolves the app's IP
Root cause of a post-deploy outage: recreating the app container can assign it a NEW docker network IP. Nginx Proxy Manager caches the app's upstream IP at config-load, so it kept connecting to the OLD IP (which, after adding the postgres/redis services, was reassigned to bizgaze-postgres) → 'Connection refused' → site down until nginx re-resolved. deploy.sh now runs 'nginx -s reload' in the NPM container after verify (normal + rollback), non-fatal if NPM isn't detected. This makes deploys self-healing for the app-IP-change case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user