From c358b44537c647997991523377b6a0b41d28fd87 Mon Sep 17 00:00:00 2001 From: "Joseph.Rawlings" Date: Wed, 24 Dec 2025 12:27:05 -0500 Subject: [PATCH] feat: add retry logic for PHP-FPM restart with optimization fallback --- gitapply.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/gitapply.sh b/gitapply.sh index f1662bf36..0d8643aec 100755 --- a/gitapply.sh +++ b/gitapply.sh @@ -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 && git pull && npm update && npm upgrade && composer upgrade && php artisan view:clear && php artisan cache:clear && php artisan optimize && systemctl restart php8.3-fpm' \ + 'cd /var/www/paymenter && git pull && npm update && npm upgrade && composer upgrade && php artisan view:clear && php artisan cache:clear && php artisan optimize && while ! systemctl restart php8.3-fpm 2>/dev/null; do echo "PHP-FPM restart failed, running optimize and retrying..."; php artisan optimize; sleep 1; done' \ > "$STATUS_DIR/${node}.log" 2>&1 if [ $? -eq 0 ]; then @@ -547,9 +547,22 @@ task_done "Optimization completed" # Restart PHP-FPM task_start "Local: Restarting Services" printf " ${C3}○${NC} PHP 8.3 FPM..." -systemctl restart php8.3-fpm & -spinner $! "PHP 8.3 FPM" -task_done "PHP 8.3 FPM restarted" + +# Retry loop: if PHP-FPM fails to restart, run optimize and try again +php_restart_success=false +php_restart_attempts=0 +while [ "$php_restart_success" = false ]; do + php_restart_attempts=$((php_restart_attempts + 1)) + if systemctl restart php8.3-fpm > /dev/null 2>&1; then + php_restart_success=true + else + printf "\r ${YELLOW}○${NC} PHP 8.3 FPM restart failed (attempt ${php_restart_attempts}), running optimize...\n" + php artisan optimize > /dev/null 2>&1 + printf " ${C3}○${NC} Retrying PHP 8.3 FPM..." + sleep 1 + fi +done +task_done "PHP 8.3 FPM restarted (attempt ${php_restart_attempts})" # Wait for remote nodes task_start "Waiting for Remote Nodes"