Improve database migration search and add service installation

Enhance database migration search logic to include the deployment directory and add a new script to install the ids-list-fetcher systemd service.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 7a657272-55ba-4a79-9a2e-f1ed9bc7a528
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: 5da210e7-b46e-46ce-a578-05f0f70545be
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/449cf7c4-c97a-45ae-8234-e5c5b8d6a84f/7a657272-55ba-4a79-9a2e-f1ed9bc7a528/zauptjn
This commit is contained in:
marco370 2025-11-27 18:20:51 +00:00
parent a08c4309a8
commit e6db06e597
3 changed files with 137 additions and 1 deletions

View File

@ -13,6 +13,7 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MIGRATIONS_DIR="$SCRIPT_DIR/migrations" MIGRATIONS_DIR="$SCRIPT_DIR/migrations"
IDS_DIR="$(dirname "$SCRIPT_DIR")" IDS_DIR="$(dirname "$SCRIPT_DIR")"
DEPLOYMENT_MIGRATIONS_DIR="$IDS_DIR/deployment/migrations"
# Carica variabili ambiente ed esportale # Carica variabili ambiente ed esportale
if [ -f "$IDS_DIR/.env" ]; then if [ -f "$IDS_DIR/.env" ]; then
@ -79,9 +80,25 @@ echo -e "${CYAN}📊 Versione database corrente: ${YELLOW}${CURRENT_VERSION}${NC
# STEP 3: Trova migrazioni da applicare # STEP 3: Trova migrazioni da applicare
# ============================================================================= # =============================================================================
# Formato migrazioni: 001_description.sql, 002_another.sql, etc. # Formato migrazioni: 001_description.sql, 002_another.sql, etc.
# Cerca in ENTRAMBE le cartelle: database-schema/migrations E deployment/migrations
MIGRATIONS_TO_APPLY=() MIGRATIONS_TO_APPLY=()
for migration_file in $(find "$MIGRATIONS_DIR" -name "[0-9][0-9][0-9]_*.sql" | sort); do # Combina migrations da entrambe le cartelle e ordina per numero
ALL_MIGRATIONS=""
if [ -d "$MIGRATIONS_DIR" ]; then
ALL_MIGRATIONS+=$(find "$MIGRATIONS_DIR" -name "[0-9][0-9][0-9]_*.sql" 2>/dev/null || true)
fi
if [ -d "$DEPLOYMENT_MIGRATIONS_DIR" ]; then
if [ -n "$ALL_MIGRATIONS" ]; then
ALL_MIGRATIONS+=$'\n'
fi
ALL_MIGRATIONS+=$(find "$DEPLOYMENT_MIGRATIONS_DIR" -name "[0-9][0-9][0-9]_*.sql" 2>/dev/null || true)
fi
# Ordina le migrations per nome file (NNN_*.sql) estraendo il basename
SORTED_MIGRATIONS=$(echo "$ALL_MIGRATIONS" | grep -v '^$' | while read f; do echo "$(basename "$f"):$f"; done | sort | cut -d':' -f2)
for migration_file in $SORTED_MIGRATIONS; do
MIGRATION_NAME=$(basename "$migration_file") MIGRATION_NAME=$(basename "$migration_file")
# Estrai numero versione dal nome file (001, 002, etc.) # Estrai numero versione dal nome file (001, 002, etc.)

View File

@ -0,0 +1,105 @@
#!/bin/bash
# =============================================================================
# IDS - Installazione Servizio List Fetcher
# =============================================================================
# Installa e configura il servizio systemd per il fetcher delle liste pubbliche
# Eseguire come ROOT: ./install_list_fetcher.sh
# =============================================================================
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}"
echo "╔═══════════════════════════════════════════════╗"
echo "║ 📋 INSTALLAZIONE IDS LIST FETCHER ║"
echo "╚═══════════════════════════════════════════════╝"
echo -e "${NC}"
IDS_DIR="/opt/ids"
SYSTEMD_DIR="/etc/systemd/system"
# Verifica di essere root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}❌ Questo script deve essere eseguito come root${NC}"
echo -e "${YELLOW} Esegui: sudo ./install_list_fetcher.sh${NC}"
exit 1
fi
# Verifica che i file sorgente esistano
SERVICE_SRC="$IDS_DIR/deployment/systemd/ids-list-fetcher.service"
TIMER_SRC="$IDS_DIR/deployment/systemd/ids-list-fetcher.timer"
if [ ! -f "$SERVICE_SRC" ]; then
echo -e "${RED}❌ File service non trovato: $SERVICE_SRC${NC}"
exit 1
fi
if [ ! -f "$TIMER_SRC" ]; then
echo -e "${RED}❌ File timer non trovato: $TIMER_SRC${NC}"
exit 1
fi
# Verifica che il virtual environment Python esista
VENV_PYTHON="$IDS_DIR/python_ml/venv/bin/python3"
if [ ! -f "$VENV_PYTHON" ]; then
echo -e "${YELLOW}⚠️ Virtual environment non trovato, creazione...${NC}"
cd "$IDS_DIR/python_ml"
python3.11 -m venv venv
./venv/bin/pip install --upgrade pip
./venv/bin/pip install -r requirements.txt
echo -e "${GREEN}✅ Virtual environment creato${NC}"
fi
# Verifica che run_fetcher.py esista
FETCHER_SCRIPT="$IDS_DIR/python_ml/list_fetcher/run_fetcher.py"
if [ ! -f "$FETCHER_SCRIPT" ]; then
echo -e "${RED}❌ Script fetcher non trovato: $FETCHER_SCRIPT${NC}"
exit 1
fi
# Copia file systemd
echo -e "${BLUE}📦 Installazione file systemd...${NC}"
cp "$SERVICE_SRC" "$SYSTEMD_DIR/ids-list-fetcher.service"
cp "$TIMER_SRC" "$SYSTEMD_DIR/ids-list-fetcher.timer"
echo -e "${GREEN} ✅ ids-list-fetcher.service installato${NC}"
echo -e "${GREEN} ✅ ids-list-fetcher.timer installato${NC}"
# Ricarica systemd
echo -e "${BLUE}🔄 Ricarica configurazione systemd...${NC}"
systemctl daemon-reload
echo -e "${GREEN}✅ Daemon ricaricato${NC}"
# Abilita e avvia timer
echo -e "${BLUE}⏱️ Abilitazione timer (ogni 10 minuti)...${NC}"
systemctl enable ids-list-fetcher.timer
systemctl start ids-list-fetcher.timer
echo -e "${GREEN}✅ Timer abilitato e avviato${NC}"
# Test esecuzione manuale
echo -e "${BLUE}🧪 Test esecuzione fetcher...${NC}"
if systemctl start ids-list-fetcher.service; then
echo -e "${GREEN}✅ Fetcher eseguito con successo${NC}"
else
echo -e "${YELLOW}⚠️ Prima esecuzione potrebbe fallire se liste non configurate${NC}"
fi
# Mostra stato
echo ""
echo -e "${GREEN}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${GREEN}║ ✅ INSTALLAZIONE COMPLETATA ║${NC}"
echo -e "${GREEN}╚═══════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${BLUE}📋 COMANDI UTILI:${NC}"
echo -e " • Stato timer: ${YELLOW}systemctl status ids-list-fetcher.timer${NC}"
echo -e " • Stato service: ${YELLOW}systemctl status ids-list-fetcher.service${NC}"
echo -e " • Esegui manuale: ${YELLOW}systemctl start ids-list-fetcher.service${NC}"
echo -e " • Visualizza logs: ${YELLOW}journalctl -u ids-list-fetcher -n 50${NC}"
echo -e " • Timer attivi: ${YELLOW}systemctl list-timers | grep ids${NC}"
echo ""

View File

@ -158,6 +158,20 @@ if [ -f "./deployment/setup_rsyslog.sh" ]; then
fi fi
fi fi
# Verifica e installa servizio list-fetcher se mancante
echo -e "\n${BLUE}📋 Verifica servizio list-fetcher...${NC}"
if ! systemctl list-unit-files | grep -q "ids-list-fetcher"; then
echo -e "${YELLOW} Servizio ids-list-fetcher non installato, installazione...${NC}"
if [ -f "./deployment/install_list_fetcher.sh" ]; then
chmod +x ./deployment/install_list_fetcher.sh
./deployment/install_list_fetcher.sh
else
echo -e "${RED} ❌ Script install_list_fetcher.sh non trovato${NC}"
fi
else
echo -e "${GREEN} ✅ Servizio ids-list-fetcher già installato${NC}"
fi
# Restart servizi # Restart servizi
echo -e "\n${BLUE}🔄 Restart servizi...${NC}" echo -e "\n${BLUE}🔄 Restart servizi...${NC}"
if [ -f "./deployment/restart_all.sh" ]; then if [ -f "./deployment/restart_all.sh" ]; then