ids.alfacom.it/deployment/run_analytics.sh
marco370 4155b0f01f Update script to use correct virtual environment path
Correct the path to the Python virtual environment in both the service definition and the wrapper script to ensure proper execution of the analytics aggregator.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Event-Id: 6b4e2246-92c4-45dd-8a8f-25a7d0067f86
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/oGXAoP7
2025-11-24 08:42:51 +00:00

64 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
#
# IDS Analytics Aggregator - Manual Execution Wrapper
# Carica credenziali da .env e esegue aggregazione
#
# Usage:
# ./run_analytics.sh hourly
# ./run_analytics.sh daily
#
set -e
# Verifica parametro
if [ "$#" -ne 1 ]; then
echo "Usage: $0 {hourly|daily}"
exit 1
fi
MODE=$1
# Verifica modo valido
if [ "$MODE" != "hourly" ] && [ "$MODE" != "daily" ]; then
echo "Errore: modo deve essere 'hourly' o 'daily'"
exit 1
fi
# Directory IDS
IDS_DIR="/opt/ids"
ENV_FILE="$IDS_DIR/.env"
SCRIPT="$IDS_DIR/python_ml/analytics_aggregator.py"
VENV="$IDS_DIR/python_ml/venv/bin/python3"
# Verifica file .env esiste
if [ ! -f "$ENV_FILE" ]; then
echo "Errore: File $ENV_FILE non trovato!"
exit 1
fi
# Verifica permessi .env (deve essere readable solo da owner)
ENV_PERMS=$(stat -c %a "$ENV_FILE")
if [ "$ENV_PERMS" != "600" ] && [ "$ENV_PERMS" != "400" ]; then
echo "Attenzione: $ENV_FILE dovrebbe avere permessi 600 (rw-------)"
echo "Esegui: chmod 600 $ENV_FILE"
fi
# Carica variabili d'ambiente e esegui aggregatore
echo "🔄 Esecuzione aggregazione $MODE..."
# Export variabili da .env
set -a
source "$ENV_FILE"
set +a
# Esegui come user ids con venv
if [ "$(whoami)" = "ids" ]; then
# Già user ids
"$VENV" "$SCRIPT" "$MODE"
else
# Switch a user ids
sudo -u ids -E "$VENV" "$SCRIPT" "$MODE"
fi
echo "✅ Aggregazione $MODE completata!"