#!/bin/bash # # Restart IDS Frontend (Node.js/Express) # Utility per restart manuale del server frontend via systemd # set -e echo "Restart Backend Node.js via systemd..." # Stop servizio echo "Stopping ids-backend..." sudo systemctl stop ids-backend.service 2>/dev/null || true sleep 2 # Kill eventuali processi orfani sulla porta 5000 echo "Liberando porta 5000..." lsof -ti:5000 | xargs kill -9 2>/dev/null || true sleep 1 # Verifica porta libera if lsof -Pi :5000 -sTCP:LISTEN -t >/dev/null 2>&1; then echo "ERRORE: Porta 5000 ancora occupata!" echo "Processi sulla porta:" lsof -i:5000 exit 1 fi echo "Porta 5000 libera" # Start servizio echo "Starting ids-backend..." sudo systemctl start ids-backend.service # Attendi avvio completo sleep 5 # Verifica avvio if systemctl is-active --quiet ids-backend.service; then echo "Backend avviato con successo" echo "Server disponibile su: http://localhost:5000" # Test rapido sleep 2 HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" http://localhost:5000/ 2>/dev/null || echo "000") if [ "$HTTP_CODE" = "200" ]; then echo "HTTP test OK (200)" else echo "HTTP test: $HTTP_CODE (potrebbe essere in fase di avvio)" fi else echo "ERRORE: Backend non avviato!" echo "Controlla log: journalctl -u ids-backend -n 20" sudo journalctl -u ids-backend -n 20 --no-pager exit 1 fi