Rende persistenti i log di produzione e protegge il deploy.

Monta /app/log sul disco video, sposta i cron log sullo stesso path, esclude log/ dal sync rsync e aggiunge pulizia volumi Docker obsoleti.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-13 09:23:42 +02:00
parent b802cf3309
commit 208664848e
9 changed files with 82 additions and 7 deletions

View File

@@ -53,8 +53,10 @@ SMTP_SSL=true
SMTP_STARTTLS=false
PASSWORD_RESET_EXPIRY_HOURS=2
# Disco video dedicato (recordings MediaMTX + dati Garage). Montare es. 800GB su /media/videos
# Disco video dedicato (recordings MediaMTX + dati Garage + log + Active Storage). Montare es. 800GB su /media/videos
MATCHLIVETV_VIDEOS_ROOT=/media/videos/matchlivetv
# Log cron e YouTube relay ffmpeg (default: ${MATCHLIVETV_VIDEOS_ROOT}/log)
# MATCHLIVETV_LOG_DIR=/media/videos/matchlivetv/log
# Replay storage — Garage (obbligatorio in produzione per Premium replay)
# Dopo il primo deploy: bash scripts/setup_garage_production.sh (crea garage.prod.toml + chiavi)

View File

@@ -131,6 +131,7 @@ services:
volumes:
- ${MATCHLIVETV_VIDEOS_ROOT:-/media/videos/matchlivetv}/recordings:/recordings
- ${MATCHLIVETV_VIDEOS_ROOT:-/media/videos/matchlivetv}/active_storage:/app/storage
- ${MATCHLIVETV_VIDEOS_ROOT:-/media/videos/matchlivetv}/log:/app/log
healthcheck:
test: ["CMD", "curl", "-f", "http://127.0.0.1:3000/up"]
interval: 15s
@@ -203,6 +204,7 @@ services:
volumes:
- ${MATCHLIVETV_VIDEOS_ROOT:-/media/videos/matchlivetv}/recordings:/recordings
- ${MATCHLIVETV_VIDEOS_ROOT:-/media/videos/matchlivetv}/active_storage:/app/storage
- ${MATCHLIVETV_VIDEOS_ROOT:-/media/videos/matchlivetv}/log:/app/log
garage:
image: dxflrs/garage:v1.0.1

View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Rimuove volumi Docker obsoleti dopo migrazione storage su disco video.
set -euo pipefail
PROJECT="${COMPOSE_PROJECT_NAME:-infra}"
remove_if_empty() {
local name="${PROJECT}_$1"
if ! docker volume inspect "$name" >/dev/null 2>&1; then
echo "Volume ${name}: assente, salto"
return 0
fi
local mount
mount="$(docker volume inspect "$name" --format '{{ .Mountpoint }}')"
if [ -n "$(sudo ls -A "$mount" 2>/dev/null || true)" ]; then
echo "Volume ${name}: non vuoto (${mount}), salto"
return 0
fi
docker volume rm "$name"
echo "Volume ${name}: rimosso"
}
echo "Pulizia volumi Docker obsoleti (progetto ${PROJECT})..."
remove_if_empty rails_storage
remove_if_empty recordings
remove_if_empty garage_data
remove_if_empty garage_meta

View File

@@ -4,13 +4,30 @@ set -euo pipefail
ROOT="${MATCHLIVETV_INFRA:-/opt/matchlivetv/infra}"
SINCE="${OPS_LOG_SCAN_SINCE:-10m}"
ENV_FILE="${ROOT}/.env"
VIDEOS_ROOT="/media/videos/matchlivetv"
TMP="$(mktemp)"
trap 'rm -f "$TMP"' EXIT
if [ -f "$ENV_FILE" ]; then
line="$(grep -E '^MATCHLIVETV_VIDEOS_ROOT=' "$ENV_FILE" 2>/dev/null | tail -1 || true)"
if [ -n "$line" ]; then
VIDEOS_ROOT="${line#MATCHLIVETV_VIDEOS_ROOT=}"
VIDEOS_ROOT="${VIDEOS_ROOT%\"}"
VIDEOS_ROOT="${VIDEOS_ROOT#\"}"
fi
fi
LOG_DIR="${MATCHLIVETV_LOG_DIR:-${VIDEOS_ROOT}/log}"
cd "$ROOT"
docker compose -f docker-compose.prod.yml logs --since "$SINCE" rails sidekiq mediamtx 2>/dev/null > "$TMP" || true
if compgen -G "${LOG_DIR}/youtube_relay_*.log" > /dev/null 2>&1; then
cat "${LOG_DIR}"/youtube_relay_*.log >> "$TMP" 2>/dev/null || true
fi
if [[ ! -s "$TMP" ]]; then
exit 0
fi

View File

@@ -5,7 +5,19 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
RUNNER="${ROOT}/scripts/cron/run_rails_task.sh"
SCAN_LOGS="${ROOT}/scripts/cron/scan_ops_logs.sh"
LOG_DIR="${MATCHLIVETV_LOG_DIR:-/opt/matchlivetv/log}"
ENV_FILE="${ROOT}/.env"
VIDEOS_ROOT="/media/videos/matchlivetv"
if [ -f "$ENV_FILE" ]; then
line="$(grep -E '^MATCHLIVETV_VIDEOS_ROOT=' "$ENV_FILE" 2>/dev/null | tail -1 || true)"
if [ -n "$line" ]; then
VIDEOS_ROOT="${line#MATCHLIVETV_VIDEOS_ROOT=}"
VIDEOS_ROOT="${VIDEOS_ROOT%\"}"
VIDEOS_ROOT="${VIDEOS_ROOT#\"}"
fi
fi
LOG_DIR="${MATCHLIVETV_LOG_DIR:-${VIDEOS_ROOT}/log}"
LOG_FILE="${LOG_DIR}/cron-replay.log"
OPS_LOG_FILE="${LOG_DIR}/cron-ops.log"
@@ -30,5 +42,6 @@ fi
echo "$CRON_BLOCK"
} | sed '/^$/d' | crontab -
echo "Log persistenti: ${LOG_DIR}"
echo "Crontab installato:"
crontab -l | grep -A3 "$MARKER"
crontab -l | grep -A4 "$MARKER"

View File

@@ -35,7 +35,17 @@ fs_rsync() {
sudo rsync -aH "$@"
}
fs_mkdir "${VIDEOS_ROOT}/recordings" "${VIDEOS_ROOT}/garage/meta" "${VIDEOS_ROOT}/garage/data" "${VIDEOS_ROOT}/active_storage"
fs_mkdir "${VIDEOS_ROOT}/recordings" "${VIDEOS_ROOT}/garage/meta" "${VIDEOS_ROOT}/garage/data" "${VIDEOS_ROOT}/active_storage" "${VIDEOS_ROOT}/log"
legacy_log_dir="/opt/matchlivetv/log"
if [ -d "$legacy_log_dir" ] && [ -n "$(ls -A "$legacy_log_dir" 2>/dev/null || true)" ]; then
if [ -z "$(ls -A "${VIDEOS_ROOT}/log" 2>/dev/null || true)" ]; then
echo "Migro log legacy ${legacy_log_dir}${VIDEOS_ROOT}/log..."
fs_rsync "${legacy_log_dir}/" "${VIDEOS_ROOT}/log/"
else
echo "Log già presenti in ${VIDEOS_ROOT}/log, salto migrazione da ${legacy_log_dir}"
fi
fi
if [ ! -w "$VIDEOS_ROOT" ]; then
sudo chown -R "$(id -un)":"$(id -gn)" "$VIDEOS_ROOT"
fi