ids.alfacom.it/deployment/check_backend.sh
marco370 203eaa9a54 Improve system stability by fixing cron job and process monitoring
Refactor cron job execution to use separate shell scripts and update process monitoring scripts to correctly handle PID files and log directories.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: f6d4ec61-7130-41dd-aef9-87b4bc73d0e8
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/3R8dKMX
2025-11-18 08:33:05 +00:00

35 lines
971 B
Bash

#!/bin/bash
# =========================================================
# CHECK BACKEND - Verifica e riavvia backend Python se necessario
# =========================================================
PROCESS_NAME="python3.11 python_ml/main.py"
PID_FILE="/var/log/ids/backend.pid"
LOG_FILE="/var/log/ids/backend.log"
WORK_DIR="/opt/ids"
mkdir -p /var/log/ids
# Check if backend is running
if pgrep -f "$PROCESS_NAME" > /dev/null; then
# Backend running, update PID
pgrep -f "$PROCESS_NAME" > "$PID_FILE"
exit 0
else
echo "[$(date)] Backend Python NON attivo, riavvio..." >> "$LOG_FILE"
# Kill any orphaned Python processes
pkill -f "python_ml/main.py" 2>/dev/null
# Wait a moment
sleep 2
# Start backend
cd "$WORK_DIR/python_ml"
nohup /usr/bin/python3.11 main.py >> "$LOG_FILE" 2>&1 &
NEW_PID=$!
echo $NEW_PID > "$PID_FILE"
echo "[$(date)] Backend riavviato con PID: $NEW_PID" >> "$LOG_FILE"
fi