Improve systemd service setup to aggressively kill manual processes
Updates `setup_systemd_services.sh` to forcefully stop existing systemd services, kill all manual Python processes owned by the `ids` user, and verify that port 8000 is free before starting the services. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: ae567421-923d-4371-a127-7bdeca91b824 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/VDRknFA
This commit is contained in:
parent
9458829ebf
commit
26f3589a7e
4
.replit
4
.replit
@ -14,6 +14,10 @@ run = ["npm", "run", "start"]
|
||||
localPort = 5000
|
||||
externalPort = 80
|
||||
|
||||
[[ports]]
|
||||
localPort = 34783
|
||||
externalPort = 3001
|
||||
|
||||
[[ports]]
|
||||
localPort = 41303
|
||||
externalPort = 3002
|
||||
|
||||
@ -0,0 +1,179 @@
|
||||
Found existing installation: joblib 1.5.2
|
||||
Uninstalling joblib-1.5.2:
|
||||
Successfully uninstalled joblib-1.5.2
|
||||
Successfully installed joblib-1.3.2
|
||||
✅ Dipendenze Python installate
|
||||
Impostazione permessi...
|
||||
|
||||
Verifica installazione:
|
||||
✅ FastAPI: 0.104.1
|
||||
✅ Uvicorn: 0.24.0
|
||||
✅ Scikit-learn: 1.3.2
|
||||
✅ Pandas: 2.1.3
|
||||
✅ HTTPX: 0.25.1
|
||||
✅ Joblib: 1.3.2
|
||||
|
||||
╔═══════════════════════════════════════════════╗
|
||||
║ ✅ DIPENDENZE PYTHON INSTALLATE ║
|
||||
╚═══════════════════════════════════════════════╝
|
||||
|
||||
NOTA:
|
||||
Il virtual environment è in: /opt/ids/python_ml/venv
|
||||
I systemd services useranno automaticamente questo venv
|
||||
|
||||
[root@ids ids]# sudo systemctl restart ids-ml-backend
|
||||
[root@ids ids]# sudo systemctl status ids-ml-backend
|
||||
● ids-ml-backend.service - IDS ML Backend (FastAPI)
|
||||
Loaded: loaded (/etc/systemd/system/ids-ml-backend.service; enabled; preset: disabled)
|
||||
Active: activating (auto-restart) (Result: exit-code) since Sat 2025-11-22 11:00:28 CET; 5s ago
|
||||
Process: 16204 ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py (code=exited, status=1/FAILURE)
|
||||
Main PID: 16204 (code=exited, status=1/FAILURE)
|
||||
CPU: 3.933s
|
||||
[root@ids ids]# sudo systemctl status ids-ml-backend
|
||||
● ids-ml-backend.service - IDS ML Backend (FastAPI)
|
||||
Loaded: loaded (/etc/systemd/system/ids-ml-backend.service; enabled; preset: disabled)
|
||||
Active: activating (auto-restart) (Result: exit-code) since Sat 2025-11-22 11:00:28 CET; 7s ago
|
||||
Process: 16204 ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py (code=exited, status=1/FAILURE)
|
||||
Main PID: 16204 (code=exited, status=1/FAILURE)
|
||||
CPU: 3.933s
|
||||
[root@ids ids]# tail -30 /var/log/ids/ml_backend.log
|
||||
from fastapi import FastAPI, HTTPException, BackgroundTasks, Security, Header
|
||||
ModuleNotFoundError: No module named 'fastapi'
|
||||
Traceback (most recent call last):
|
||||
File "/opt/ids/python_ml/main.py", line 12, in <module>
|
||||
import pandas as pd
|
||||
ModuleNotFoundError: No module named 'pandas'
|
||||
Traceback (most recent call last):
|
||||
File "/opt/ids/python_ml/main.py", line 20, in <module>
|
||||
from ml_analyzer import MLAnalyzer
|
||||
File "/opt/ids/python_ml/ml_analyzer.py", line 8, in <module>
|
||||
from sklearn.ensemble import IsolationForest
|
||||
ModuleNotFoundError: No module named 'sklearn'
|
||||
INFO: Started server process [16144]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
Starting IDS API on http://0.0.0.0:8000
|
||||
Docs available at http://0.0.0.0:8000/docs
|
||||
INFO: Started server process [16204]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
Starting IDS API on http://0.0.0.0:8000
|
||||
Docs available at http://0.0.0.0:8000/docs
|
||||
[root@ids ids]# sudo systemctl status ids-ml-backend
|
||||
● ids-ml-backend.service - IDS ML Backend (FastAPI)
|
||||
Loaded: loaded (/etc/systemd/system/ids-ml-backend.service; enabled; preset: disabled)
|
||||
Active: active (running) since Sat 2025-11-22 11:01:03 CET; 1s ago
|
||||
Main PID: 16291 (python3)
|
||||
Tasks: 15 (limit: 100409)
|
||||
Memory: 100.2M (max: 2.0G available: 1.9G)
|
||||
CPU: 3.101s
|
||||
CGroup: /system.slice/ids-ml-backend.service
|
||||
└─16291 /opt/ids/python_ml/venv/bin/python3 main.py
|
||||
|
||||
Nov 22 11:01:03 ids.alfacom.it systemd[1]: Started IDS ML Backend (FastAPI).
|
||||
[root@ids ids]# sudo systemctl status ids-ml-backend
|
||||
● ids-ml-backend.service - IDS ML Backend (FastAPI)
|
||||
Loaded: loaded (/etc/systemd/system/ids-ml-backend.service; enabled; preset: disabled)
|
||||
Active: activating (auto-restart) (Result: exit-code) since Sat 2025-11-22 11:01:05 CET; 9s ago
|
||||
Process: 16291 ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py (code=exited, status=1/FAILURE)
|
||||
Main PID: 16291 (code=exited, status=1/FAILURE)
|
||||
CPU: 3.804s
|
||||
[root@ids ids]# sudo systemctl status ids-ml-backend
|
||||
● ids-ml-backend.service - IDS ML Backend (FastAPI)
|
||||
Loaded: loaded (/etc/systemd/system/ids-ml-backend.service; enabled; preset: disabled)
|
||||
Active: activating (auto-restart) (Result: exit-code) since Sat 2025-11-22 11:01:17 CET; 251ms ago
|
||||
Process: 16321 ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py (code=exited, status=1/FAILURE)
|
||||
Main PID: 16321 (code=exited, status=1/FAILURE)
|
||||
CPU: 3.840s
|
||||
[root@ids ids]# tail -30 /var/log/ids/ml_backend.log
|
||||
[LOAD] Modello caricato da models
|
||||
Starting IDS API on http://0.0.0.0:8000
|
||||
Docs available at http://0.0.0.0:8000/docs
|
||||
INFO: Started server process [16257]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
Starting IDS API on http://0.0.0.0:8000
|
||||
Docs available at http://0.0.0.0:8000/docs
|
||||
INFO: Started server process [16291]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
Starting IDS API on http://0.0.0.0:8000
|
||||
Docs available at http://0.0.0.0:8000/docs
|
||||
INFO: Started server process [16321]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
Starting IDS API on http://0.0.0.0:8000
|
||||
Docs available at http://0.0.0.0:8000/docs
|
||||
[root@ids ids]# sudo systemctl status ids-ml-backend
|
||||
● ids-ml-backend.service - IDS ML Backend (FastAPI)
|
||||
Loaded: loaded (/etc/systemd/system/ids-ml-backend.service; enabled; preset: disabled)
|
||||
Active: active (running) since Sat 2025-11-22 11:01:27 CET; 2s ago
|
||||
Main PID: 16348 (python3)
|
||||
Tasks: 19 (limit: 100409)
|
||||
Memory: 118.4M (max: 2.0G available: 1.8G)
|
||||
CPU: 3.872s
|
||||
CGroup: /system.slice/ids-ml-backend.service
|
||||
└─16348 /opt/ids/python_ml/venv/bin/python3 main.py
|
||||
|
||||
Nov 22 11:01:27 ids.alfacom.it systemd[1]: Started IDS ML Backend (FastAPI).
|
||||
[root@ids ids]# sudo systemctl status ids-ml-backend
|
||||
● ids-ml-backend.service - IDS ML Backend (FastAPI)
|
||||
Loaded: loaded (/etc/systemd/system/ids-ml-backend.service; enabled; preset: disabled)
|
||||
Active: activating (auto-restart) (Result: exit-code) since Sat 2025-11-22 11:01:30 CET; 4s ago
|
||||
Process: 16348 ExecStart=/opt/ids/python_ml/venv/bin/python3 main.py (code=exited, status=1/FAILURE)
|
||||
Main PID: 16348 (code=exited, status=1/FAILURE)
|
||||
CPU: 3.911s
|
||||
|
||||
Nov 22 11:01:30 ids.alfacom.it systemd[1]: ids-ml-backend.service: Failed with result 'exit-code'.
|
||||
Nov 22 11:01:30 ids.alfacom.it systemd[1]: ids-ml-backend.service: Consumed 3.911s CPU time.
|
||||
[root@ids ids]# tail -30 /var/log/ids/ml_backend.log
|
||||
[LOAD] Modello caricato da models
|
||||
🚀 Starting IDS API on http://0.0.0.0:8000
|
||||
📚 Docs available at http://0.0.0.0:8000/docs
|
||||
INFO: Started server process [16291]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
🚀 Starting IDS API on http://0.0.0.0:8000
|
||||
📚 Docs available at http://0.0.0.0:8000/docs
|
||||
INFO: Started server process [16321]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
🚀 Starting IDS API on http://0.0.0.0:8000
|
||||
📚 Docs available at http://0.0.0.0:8000/docs
|
||||
INFO: Started server process [16348]
|
||||
INFO: Waiting for application startup.
|
||||
INFO: Application startup complete.
|
||||
ERROR: [Errno 98] error while attempting to bind on address ('0.0.0.0', 8000): address already in use
|
||||
INFO: Waiting for application shutdown.
|
||||
INFO: Application shutdown complete.
|
||||
[LOAD] Modello caricato da models
|
||||
🚀 Starting IDS API on http://0.0.0.0:8000
|
||||
📚 Docs available at http://0.0.0.0:8000/docs
|
||||
@ -57,12 +57,27 @@ cp "${SYSTEMD_DIR}/ids-syslog-parser.service" /etc/systemd/system/
|
||||
echo -e "${BLUE}♻️ Reload systemd daemon...${NC}"
|
||||
systemctl daemon-reload
|
||||
|
||||
# Stop processi manuali esistenti (se presenti)
|
||||
echo -e "${YELLOW}⏸️ Fermando processi manuali esistenti...${NC}"
|
||||
pkill -f "python.*main.py" || true
|
||||
pkill -f "python.*syslog_parser.py" || true
|
||||
# Stop servizi systemd esistenti (se presenti)
|
||||
echo -e "${YELLOW}⏸️ Fermando servizi systemd esistenti...${NC}"
|
||||
systemctl stop ids-ml-backend.service 2>/dev/null || true
|
||||
systemctl stop ids-syslog-parser.service 2>/dev/null || true
|
||||
sleep 1
|
||||
|
||||
# Kill TUTTI i processi Python manuali dell'utente ids
|
||||
echo -e "${YELLOW}🧹 Pulizia processi Python manuali...${NC}"
|
||||
pkill -9 -u ids -f "python.*main.py" 2>/dev/null || true
|
||||
pkill -9 -u ids -f "python.*syslog_parser.py" 2>/dev/null || true
|
||||
sleep 2
|
||||
|
||||
# Verifica che porta 8000 sia libera
|
||||
if lsof -Pi :8000 -sTCP:LISTEN -t >/dev/null 2>&1; then
|
||||
echo -e "${RED}⚠️ Porta 8000 ancora occupata, killing processo...${NC}"
|
||||
lsof -ti:8000 | xargs kill -9 2>/dev/null || true
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}✅ Pulizia completata${NC}"
|
||||
|
||||
# Enable e start services
|
||||
echo -e "${BLUE}🚀 Attivazione servizi...${NC}"
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user