#!/usr/bin/env bash set -euo pipefail root="$(cd "$(dirname "$0")/.." && pwd)" mkdir -p "$root/logs" pidfile="$root/logs/camera.pid" if [[ -f "$pidfile" ]]; then pid=$(cat "$pidfile") if [[ "$pid" =~ ^[0-9]+$ ]] && kill -0 "$pid" 2>/dev/null && grep -zFq "$root/run_camera.py" "/proc/$pid/cmdline"; then echo "Already running: PID $pid"; exit 0 fi fi nohup "$root/run_camera.sh" --output "$root/outputs/live" "$@" > "$root/logs/live.log" 2>&1 < /dev/null & pid=$!; echo "$pid" > "$pidfile" sleep 2 if ! kill -0 "$pid" 2>/dev/null; then tail -30 "$root/logs/live.log"; exit 1; fi echo "Started PID $pid; log: $root/logs/live.log" for option in "$@"; do if [[ "$option" == --visualize ]]; then echo "Visualization requested; see log for startup status (default port 8765)." fi done