From cc7a0f6f0f42310d26b13224fc4a7f97a551c55e Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Mon, 16 Feb 2026 14:48:50 +0000 Subject: [PATCH] Update scripts to properly manage backend and frontend services Adjusted `check_frontend.sh` and `restart_all.sh` to use `systemctl` for the ML backend and direct process management for the frontend, resolving issues with incorrect Python environments and process termination. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: cb6e0872-24a9-4a4b-a053-9491c053b13f Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/4aeldgV --- deployment/check_frontend.sh | 33 +++++++++++++++++++-------------- deployment/restart_all.sh | 20 +++++++++++++------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/deployment/check_frontend.sh b/deployment/check_frontend.sh index e21f02c..d927e29 100755 --- a/deployment/check_frontend.sh +++ b/deployment/check_frontend.sh @@ -1,28 +1,33 @@ #!/bin/bash # ========================================================= # CHECK FRONTEND - Verifica e riavvia frontend Node.js se necessario -# Usa systemctl per gestire il servizio # ========================================================= LOG_FILE="/var/log/ids/frontend.log" +WORK_DIR="/opt/ids" mkdir -p /var/log/ids -# Check if systemd service is active -if systemctl is-active --quiet ids-frontend; then +# Check if frontend (vite/node) is running +if pgrep -f "vite" > /dev/null || pgrep -f "node.*server" > /dev/null; then exit 0 else - echo "[$(date)] Frontend Node NON attivo, riavvio via systemctl..." >> "$LOG_FILE" - - # Restart via systemctl - systemctl restart ids-frontend - - # Wait for startup - sleep 3 - - if systemctl is-active --quiet ids-frontend; then - echo "[$(date)] Frontend riavviato con successo via systemctl" >> "$LOG_FILE" + echo "[$(date)] Frontend Node NON attivo, riavvio..." >> "$LOG_FILE" + + # Start frontend with environment variables from .env + cd "$WORK_DIR" + if [ -f "$WORK_DIR/.env" ]; then + nohup env $(cat "$WORK_DIR/.env" | grep -v '^#' | xargs) npm run dev >> "$LOG_FILE" 2>&1 & else - echo "[$(date)] ERRORE: Frontend non si è avviato. Controlla: journalctl -u ids-frontend" >> "$LOG_FILE" + nohup npm run dev >> "$LOG_FILE" 2>&1 & + fi + NEW_PID=$! + + sleep 3 + + if pgrep -f "vite" > /dev/null; then + echo "[$(date)] Frontend riavviato con successo (PID: $NEW_PID)" >> "$LOG_FILE" + else + echo "[$(date)] ERRORE: Frontend non si è avviato" >> "$LOG_FILE" fi fi diff --git a/deployment/restart_all.sh b/deployment/restart_all.sh index ea27bb0..e56bbd9 100755 --- a/deployment/restart_all.sh +++ b/deployment/restart_all.sh @@ -1,17 +1,20 @@ #!/bin/bash # ========================================================= # RESTART ALL - Riavvio completo sistema IDS -# Usa systemctl per gestire tutti i servizi +# Usa systemctl per ML Backend, processo diretto per frontend # ========================================================= LOG_FILE="/var/log/ids/cron.log" echo "$(date): === RESTART SETTIMANALE SISTEMA IDS ===" >> "$LOG_FILE" -# Stop all services via systemctl +# Stop ML Backend via systemctl echo "$(date): Arresto servizi..." >> "$LOG_FILE" systemctl stop ids-ml-backend 2>/dev/null -systemctl stop ids-frontend 2>/dev/null + +# Stop frontend processes +pkill -f "vite" 2>/dev/null +pkill -f "npm run dev" 2>/dev/null sleep 5 @@ -20,20 +23,23 @@ echo "$(date): Pulizia file temporanei..." >> "$LOG_FILE" rm -f /var/log/ids/*.pid find /tmp -name "ids_*" -mtime +7 -delete 2>/dev/null -# Restart services via systemctl +# Restart ML Backend via systemctl echo "$(date): Riavvio servizi..." >> "$LOG_FILE" systemctl start ids-ml-backend sleep 3 -systemctl start ids-frontend -# Verify +# Restart frontend via check script +/opt/ids/deployment/check_frontend.sh >> "$LOG_FILE" 2>&1 + +# Verify ML Backend if systemctl is-active --quiet ids-ml-backend; then echo "$(date): ML Backend avviato con successo" >> "$LOG_FILE" else echo "$(date): ERRORE: ML Backend non si è avviato" >> "$LOG_FILE" fi -if systemctl is-active --quiet ids-frontend; then +# Verify Frontend +if pgrep -f "vite" > /dev/null; then echo "$(date): Frontend avviato con successo" >> "$LOG_FILE" else echo "$(date): ERRORE: Frontend non si è avviato" >> "$LOG_FILE"