#!/usr/bin/env bash # Thin wrapper around `streamd serve` lifecycle commands. # Prefer calling the binary directly: # ./streamd serve start|stop|restart|status # # Kept so older docs/curl installs that fetch streamd-bg.sh still work. set -euo pipefail ROOT="$(cd "$(dirname "$0")" && pwd)" cd "$ROOT" BIN="${STREAMD_BIN:-$ROOT/streamd}" [[ -x "$BIN" ]] || { echo "streamd-bg: missing executable $BIN" >&2; exit 1; } cmd="${1:-}" shift || true case "$cmd" in start|stop|restart|status) exec "$BIN" serve "$cmd" "$@" ;; log) # Resolve log file from streamd.yaml when possible; else streamd.log log="$ROOT/streamd.log" if [[ -f "$ROOT/streamd.yaml" ]]; then # shellcheck disable=SC2016 ylog="$(grep -E '^log_file:' "$ROOT/streamd.yaml" | head -1 | sed 's/^log_file:[[:space:]]*//;s/[[:space:]]*$//;s/^["'\'']//;s/["'\'']$//')" || true if [[ -n "${ylog:-}" ]]; then if [[ "$ylog" = /* ]]; then log="$ylog"; else log="$ROOT/$ylog"; fi fi fi exec tail -n 100 -f "$log" ;; start-agent) cfg="${AGENT_CONFIG:-$ROOT/agent.yaml}" [[ -f "$cfg" ]] || { echo "streamd-bg: missing $cfg" >&2; exit 1; } nohup "$BIN" agent run --config "$cfg" >"$ROOT/agent.log" 2>&1 & echo $! >"$ROOT/agent.pid" echo "agent started pid=$(cat "$ROOT/agent.pid")" ;; stop-agent) if [[ -f "$ROOT/agent.pid" ]]; then kill "$(cat "$ROOT/agent.pid")" 2>/dev/null || true rm -f "$ROOT/agent.pid" echo "agent stopped" else echo "agent is not running" fi ;; log-agent) exec tail -n 100 -f "$ROOT/agent.log" ;; -h|--help|help|"") cat < Preferred (same machine): ./streamd serve start|stop|restart|status|update This wrapper still accepts: start | stop | restart | status | log start-agent | stop-agent | log-agent EOF [[ -n "$cmd" ]] || exit 2 ;; *) echo "streamd-bg: unknown command: $cmd (try --help)" >&2 exit 1 ;; esac