Files
MatchLiveTv/scripts/deploy/bootstrap_stream_node.sh
T
eminuxandCursor 05ef56c56d Aggiunge replay YouTube temporaneo, pull registrazioni dai CPX e snapshot ingest in admin.
Così overflow Hetzner e VOD YouTube restano in archivio dopo lo spegnimento del nodo, e la colonna ingest non si svuota.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-28 13:01:41 +02:00

49 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# Installa slate + relay-agent su un CPX già provisionato (una tantum, non per ogni diretta).
# STREAM_NODE_HOST=116.203.217.194 bash scripts/deploy/bootstrap_stream_node.sh
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
HOST="${STREAM_NODE_HOST:?Imposta STREAM_NODE_HOST (IPv4 pubblico del CPX)}"
SSH_KEY="${STREAM_NODE_SSH_KEY_HOST:-$HOME/.ssh/matchlivetv_stream_hetzner}"
SECRET="${STREAM_NODE_AGENT_SECRET:-mediamtx_webhook_dev_secret}"
SSH=(ssh -i "$SSH_KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o IdentitiesOnly=yes "root@$HOST")
SCP=(scp -i "$SSH_KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new -o IdentitiesOnly=yes)
if [[ ! -f "$ROOT/infra/slates/offline.mp4" ]]; then
(cd "$ROOT/infra" && bash scripts/generate_slate.sh)
fi
"${SSH[@]}" "apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y python3 fonts-dejavu-core ffmpeg >/dev/null"
"${SSH[@]}" "mkdir -p /opt/stream-node /slates /var/log"
"${SCP[@]}" "$ROOT/infra/stream-node/relay-agent.py" "root@$HOST:/opt/stream-node/relay-agent.py"
"${SCP[@]}" "$ROOT/infra/slates/offline.mp4" "root@$HOST:/slates/offline.mp4"
"${SSH[@]}" "chmod 755 /opt/stream-node/relay-agent.py"
"${SSH[@]}" "cat >/opt/stream-node/agent.env <<EOF
STREAM_NODE_AGENT_SECRET=${SECRET}
STREAM_NODE_AGENT_LISTEN=0.0.0.0:9100
STREAM_NODE_LOCAL_HLS_URL=http://127.0.0.1:8888
STREAM_NODE_RELAY_LOG_DIR=/var/log
STREAM_NODE_SLATES_DIR=/slates/custom
STREAM_NODE_RECORDINGS_DIR=/recordings
EOF
chmod 600 /opt/stream-node/agent.env"
"${SSH[@]}" "cat >/etc/systemd/system/mltv-relay-agent.service <<'EOF'
[Unit]
Description=Match Live TV YouTube relay agent
After=network-online.target
[Service]
Type=simple
EnvironmentFile=/opt/stream-node/agent.env
ExecStart=/usr/bin/python3 /opt/stream-node/relay-agent.py
Restart=always
RestartSec=2
[Install]
WantedBy=multi-user.target
EOF
pkill -f 'ffmpeg -nostdin' || true
systemctl daemon-reload
systemctl enable --now mltv-relay-agent.service
systemctl restart mltv-relay-agent.service
curl -fsS http://127.0.0.1:9100/health"
echo "bootstrap ok host=${HOST}"