feat: implement maintenance mode handling for remote nodes in gitapply.sh

This commit is contained in:
2025-12-24 09:32:37 -05:00
parent 700e803622
commit bc340c83f0

View File

@@ -64,7 +64,7 @@ NODES=(
"10.0.254.131"
)
MAX_RETRIES=3
MAX_RETRIES=100
# Get current node IP
CURRENT_IP=$(hostname -I | awk '{print $1}')
@@ -244,7 +244,7 @@ run_remote_update() {
echo "pending" > "$status_file"
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -o BatchMode=yes -i "$SSH_KEY" root@"$node" \
'cd /var/www/paymenter && php artisan down && git pull && npm update && npm upgrade && composer upgrade && php artisan view:clear && php artisan cache:clear && php artisan optimize && systemctl restart php8.3-fpm && php artisan up' \
'cd /var/www/paymenter && git pull && npm update && npm upgrade && composer upgrade && php artisan view:clear && php artisan cache:clear && php artisan optimize && systemctl restart php8.3-fpm' \
> "$STATUS_DIR/${node}.log" 2>&1
if [ $? -eq 0 ]; then
@@ -256,6 +256,18 @@ run_remote_update() {
fi
}
run_remote_maintenance_down() {
local node=$1
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o BatchMode=yes -i "$SSH_KEY" root@"$node" \
'cd /var/www/paymenter && php artisan down' > /dev/null 2>&1
}
run_remote_maintenance_up() {
local node=$1
ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 -o BatchMode=yes -i "$SSH_KEY" root@"$node" \
'cd /var/www/paymenter && php artisan up' > /dev/null 2>&1
}
get_remote_nodes() {
local remotes=()
for node in "${NODES[@]}"; do
@@ -439,12 +451,21 @@ cd /var/www/paymenter
task_start "Preparing Update"
countdown "$sleep_time"
# Enable Maintenance Mode
task_start "Local: Enabling Maintenance Mode"
printf " ${C3}○${NC} Putting application in maintenance mode..."
# Enable Maintenance Mode on All Nodes
task_start "Cluster: Enabling Maintenance Mode"
printf " ${C3}○${NC} Putting all nodes in maintenance mode..."
# Start maintenance mode on all remote nodes in parallel
for node in "${REMOTE_NODES[@]}"; do
run_remote_maintenance_down "$node" &
done
# Also put local node in maintenance mode
php artisan down > /dev/null 2>&1 &
spinner $! "Maintenance mode"
task_done "Maintenance mode enabled"
# Wait for all maintenance commands to complete
wait
task_done "All nodes in maintenance mode"
# Deploy with progress
task_start "Deploying to Remote Nodes"
@@ -567,11 +588,20 @@ done
print_node_grid "Final Cluster Status" "true" "${REMOTE_NODES[@]}"
# Disable Maintenance Mode
task_start "Local: Disabling Maintenance Mode"
printf " ${C3}○${NC} Bringing application back online..."
# Disable Maintenance Mode on All Nodes
task_start "Cluster: Disabling Maintenance Mode"
printf " ${C3}○${NC} Bringing all nodes back online..."
# Bring all remote nodes up in parallel
for node in "${REMOTE_NODES[@]}"; do
run_remote_maintenance_up "$node" &
done
# Also bring local node up
php artisan up > /dev/null 2>&1 &
spinner $! "Bringing online"
task_done "Application is back online"
# Wait for all nodes to come up
wait
task_done "All nodes are back online"
print_complete