27 lines
812 B
Bash
27 lines
812 B
Bash
#!/bin/bash
|
|
# Zero-Downtime Reload Script
|
|
# Validates config first, then reloads NGINX gracefully.
|
|
|
|
CONTAINER_NAME="nginx-proxy"
|
|
|
|
echo "[Reload] Checking configuration in $CONTAINER_NAME..."
|
|
|
|
# 1. Validate Configuration (nginx -t)
|
|
if docker exec "$CONTAINER_NAME" nginx -t; then
|
|
echo "[Reload] Configuration is VALID."
|
|
else
|
|
echo "[Reload] ❌ Configuration is INVALID. Aborting reload."
|
|
exit 1
|
|
fi
|
|
|
|
# 2. Graceful Reload (nginx -s reload)
|
|
# This starts new workers with new config, while old workers finish requests.
|
|
echo "[Reload] Triggering graceful reload..."
|
|
if docker exec "$CONTAINER_NAME" nginx -s reload; then
|
|
echo "[Reload] ✅ Reload signal sent successfully."
|
|
echo "[Reload] Zero-downtime update in progress."
|
|
else
|
|
echo "[Reload] ❌ Failed to send reload signal."
|
|
exit 1
|
|
fi
|