Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243#!/bin/bash# Waits for the ingest chain (download -> encode -> card) to finish, then# installs and starts the launchd service. Safe to re-run; it replaces any# existing service instance.set -ucd "$(dirname "$0")/.."
echo "$(date '+%F %T') waiting for ingest to complete..."until grep -q "card written" logs/ingest.log 2>/dev/null; do if grep -q "failures:" logs/ingest.log 2>/dev/null; then echo "$(date '+%F %T') ingest reported failures; not going live." && exit 1 fi sleep 120done
# Give the second pass (re-sourced films) up to 40 minutes to finish, then# launch regardless; stragglers join the playlist on the next shuffle cycle.waited=0until grep -q "SECOND PASS DONE" logs/ingest2.log 2>/dev/null || (( waited >= 2400 )); do sleep 120; waited=$(( waited + 120 ))doneecho "$(date '+%F %T') second pass: $(grep -c 'SECOND PASS DONE' logs/ingest2.log 2>/dev/null || echo 0) done flag, waited ${waited}s"
n=$(ls encoded/*.mp4 2>/dev/null | wc -l | tr -d ' ')echo "$(date '+%F %T') ingest complete: $n encoded films"if (( n < 60 )); then echo "only $n encodes present; expected ~68. Not going live." && exit 1fi
mkdir -p ~/Library/LaunchAgentscp launchd/town.laugh.stream.plist ~/Library/LaunchAgents/launchctl bootout "gui/$(id -u)/town.laugh.stream" 2>/dev/null || truelaunchctl bootstrap "gui/$(id -u)" ~/Library/LaunchAgents/town.laugh.stream.plistecho "$(date '+%F %T') service started; checking stability..."sleep 90if pgrep -f "f flv rtmps://stream.place" > /dev/null; then echo "$(date '+%F %T') LIVE: ffmpeg is streaming to stream.place"else echo "$(date '+%F %T') ffmpeg not running after 90s; see logs/stream.log" tail -5 logs/stream.log exit 1fi