From 0fe3a51887040eab8e4a6f39cc84d8f38eb64f56 Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Thu, 16 Oct 2025 14:21:26 +0000 Subject: [PATCH] Improve application restart process by robustly locating PM2 Add logic to reliably find and use the PM2 executable for application restarts, ensuring consistency across different environments. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 42d8028a-fa71-4ec2-938c-e43eedf7df01 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/42d8028a-fa71-4ec2-938c-e43eedf7df01/eg9yHD6 --- .replit | 4 ---- deploy/deploy.sh | 27 +++++++++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.replit b/.replit index 597ad14..048618b 100644 --- a/.replit +++ b/.replit @@ -19,10 +19,6 @@ externalPort = 80 localPort = 33035 externalPort = 3001 -[[ports]] -localPort = 36403 -externalPort = 3003 - [[ports]] localPort = 41343 externalPort = 3000 diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 253c0d7..b208e73 100644 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -69,24 +69,35 @@ echo "๐Ÿงน Pulizia devDependencies (mantiene solo production)..." npm prune --production # =================== RESTART APPLICATION =================== +# Trova PM2 (potrebbe essere in vari percorsi) +PM2_CMD=$(which pm2 2>/dev/null || echo "/usr/local/bin/pm2") +if [ ! -x "$PM2_CMD" ]; then + PM2_CMD="/usr/bin/pm2" +fi +if [ ! -x "$PM2_CMD" ]; then + PM2_CMD="$(npm root -g)/pm2/bin/pm2" +fi + +echo "๐Ÿ” Usando PM2: $PM2_CMD" + # Restart applicazione con PM2 echo "๐Ÿ”„ Restart applicazione..." -if pm2 show $APP_NAME > /dev/null 2>&1; then - pm2 reload $APP_NAME --update-env +if $PM2_CMD show $APP_NAME > /dev/null 2>&1; then + $PM2_CMD reload $APP_NAME --update-env else - pm2 start npm --name $APP_NAME -- start - pm2 save + $PM2_CMD start npm --name $APP_NAME -- start + $PM2_CMD save fi # Health check echo "๐Ÿฅ Health check..." sleep 5 -if pm2 show $APP_NAME | grep -q "online"; then +if $PM2_CMD show $APP_NAME | grep -q "online"; then echo "โœ… Deployment completato con successo!" - pm2 logs $APP_NAME --lines 20 --nostream + $PM2_CMD logs $APP_NAME --lines 20 --nostream else echo "โŒ Errore: applicazione non online" - pm2 logs $APP_NAME --lines 50 --nostream + $PM2_CMD logs $APP_NAME --lines 50 --nostream # Rollback: ripristina ultimo backup echo "๐Ÿ”„ Tentativo rollback backup..." @@ -103,7 +114,7 @@ fi # =================== STATUS =================== echo "" echo "๐Ÿ“Š Status PM2:" -pm2 status +$PM2_CMD status echo "" echo "๐Ÿ“ˆ Ultimi backup disponibili:"