#!/usr/bin/env bash set -euo pipefail # Usage: ./scripts/check_relay.sh # Relies on .env REACT_APP_CORE_URL and optional API_TOKEN if [ -f .env ]; then export $(grep -v '^#' .env | xargs) || true fi CORE_URL=${REACT_APP_CORE_URL:-http://localhost:8080} API_TOKEN=${API_TOKEN:-} if [ "$#" -lt 1 ]; then echo "Usage: $0 " exit 2 fi CHANNEL_ID=$1 AUTH_HEADER=() if [ -n "$API_TOKEN" ]; then AUTH_HEADER+=( -H "Authorization: Bearer ${API_TOKEN}" ) fi echo "Checking relay and ingest state for channel: ${CHANNEL_ID} (CORE: ${CORE_URL})" echo -e "\n1) WebRTC relay (node) status -> /webrtc-relay/status" curl -s ${AUTH_HEADER[@]} "${CORE_URL}/webrtc-relay/status" | jq '.' || echo "(no response)" echo -e "\n2) RTMP channels -> /api/v3/rtmp" curl -s ${AUTH_HEADER[@]} "${CORE_URL}/api/v3/rtmp" | jq '.' || echo "(no response)" echo -e "\n3) Active sessions (ffmpeg,hls,rtmp,srt) -> /api/v3/session/active" curl -s ${AUTH_HEADER[@]} -X POST "${CORE_URL}/api/v3/metrics" -H 'Content-Type: application/json' -d '{"query":{},"range":{}}' >/dev/null 2>&1 || true # preferred: /api/v3/session/active?collectors=ffmpeg,hls,rtmp,srt curl -s ${AUTH_HEADER[@]} "${CORE_URL}/api/v3/session/active?collectors=ffmpeg,hls,rtmp,srt" | jq '.' || echo "(no response)" echo -e "\n4) Processes referencing channel -> /api/v3/process?reference=${CHANNEL_ID}" curl -s ${AUTH_HEADER[@]} "${CORE_URL}/api/v3/process?reference=${CHANNEL_ID}" | jq '.' || echo "(no response)" echo -e "\n5) Ingest process state/report (if any)" # Try to extract ingest process id from process list proc_ids=$(curl -s ${AUTH_HEADER[@]} "${CORE_URL}/api/v3/process?reference=${CHANNEL_ID}" | jq -r '.[]?.id' || true) if [ -n "$proc_ids" ]; then for id in $proc_ids; do echo -e "\n--- process: $id ---" curl -s ${AUTH_HEADER[@]} "${CORE_URL}/api/v3/process/${id}/state" | jq '.' || echo "(no state)" curl -s ${AUTH_HEADER[@]} "${CORE_URL}/api/v3/process/${id}/report" | jq '.' || echo "(no report)" done else echo "No processes found for reference ${CHANNEL_ID}" fi echo -e "\n6) MemFS files for channel -> /api/v3/fs/mem?glob=/${CHANNEL_ID}*" curl -s ${AUTH_HEADER[@]} "${CORE_URL}/api/v3/fs/mem?glob=/%2F${CHANNEL_ID}%2A" | jq '.' || echo "(no response)" echo -e "\nHint: Check server logs (node) for [webrtc-relay] and core logs for ffmpeg/process messages. If using Docker, run: docker-compose logs -f"