#!/bin/sh set -eu ROOT="$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)" PORT="${DOUYIN_WORKBENCH_PORT:-3618}" SCRIPT="$ROOT/scripts/douyin-browser-capture/control_panel.mjs" LOG_FILE="${DOUYIN_WORKBENCH_LOG:-/tmp/storyforge-douyin-workbench.log}" if lsof -nP -iTCP:"$PORT" -sTCP:LISTEN >/dev/null 2>&1; then echo "douyin workbench already running: http://127.0.0.1:$PORT/workbench" exit 0 fi nohup env PORT="$PORT" node "$SCRIPT" >"$LOG_FILE" 2>&1 & python3 - <<'PY' import os import time import urllib.request port = os.environ.get("PORT", "3618") url = f"http://127.0.0.1:{port}/workbench" deadline = time.time() + 15 last_error = "" while time.time() < deadline: try: with urllib.request.urlopen(url, timeout=3) as resp: print(f"douyin workbench ready: {resp.status} {url}") raise SystemExit(0) except Exception as exc: last_error = str(exc) time.sleep(0.5) print(f"douyin workbench start timeout: {last_error}") raise SystemExit(1) PY