From cb483c0824195df429f9fe0c7ff843de8c4d6190 Mon Sep 17 00:00:00 2001 From: jetson Date: Tue, 20 Oct 2026 15:49:15 +0700 Subject: [PATCH] Revert "feat: reverse SSH tunnel so FCP (.96) reaches recounter via 127.0.0.1:9050" This reverts commit e3a905e1704895962e91aa65e36ed2b813be82c8. --- CHANGELOG.md | 7 ------ docs/ai-handoff-fcp-recount.md | 27 +--------------------- start_dashboard.sh | 6 ----- start_tunnel.sh | 41 ---------------------------------- stop_dashboard.sh | 4 ---- stop_tunnel.sh | 10 --------- 6 files changed, 1 insertion(+), 94 deletions(-) delete mode 100755 start_tunnel.sh delete mode 100755 stop_tunnel.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 459d375..28dd28b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,13 +7,6 @@ version tags are cut in this repo — `main` is the release line). ## [Unreleased] ### Added -- **Reverse SSH tunnel** `start_tunnel.sh` / `stop_tunnel.sh` - (`192.168.192.96` ↔ `.93`): .93 dials out to .96 and publishes recounter - as `127.0.0.1:9050` **on .96**, because .96→.93 inbound is firewalled - (100% loss). FCP now calls `RECOUNTER_URL=http://127.0.0.1:9050` — - recounter "at .96's IP", counting on .93 hardware. Auto-started by - `start_dashboard.sh` (skip: `SKIP_TUNNEL=1`). E2E verified: analyze - POST from .96 → job COMPLETED on .93. - **`POST /api/analyze` machine endpoint** (`540e1b5`): multipart video + `fcp_mode` letter (A–D) or explicit `model_stems`; returns **202** `{"job_id","status_url"}`; **409 busy** guard when any job is diff --git a/docs/ai-handoff-fcp-recount.md b/docs/ai-handoff-fcp-recount.md index 41fb193..7cbfcc0 100644 --- a/docs/ai-handoff-fcp-recount.md +++ b/docs/ai-handoff-fcp-recount.md @@ -84,31 +84,6 @@ Everything needed is already in FCP (researched, file:line verified): different data attribute (e.g. `data-recount`) and its own `apply*State` fn — do not reuse `data-batch`. -## 1b. NETWORK — how FCP reaches recounter across the firewall (SOLVED) - -**Problem:** FCP host `192.168.192.96` cannot initiate connections to -recounter host `192.168.192.93` — .93's firewall (ufw active) drops NEW -inbound connections (100% ping loss .96→.93, while .93→.96 works fine). - -**Solution — reverse SSH tunnel (working, E2E-tested 2026-10-20):** -- `.93` dials OUT to `.96` (`ssh -R 127.0.0.1:9050:127.0.0.1:9050`) — - outbound from .93 is allowed. -- `.96` then serves recounter on **its own loopback** → FCP calls - `RECOUNTER_URL=http://127.0.0.1:9050` — literally "recounter at .96's - IP", counting on .93 hardware. -- Scripts: `start_tunnel.sh` / `stop_tunnel.sh` (auto-started by - `start_dashboard.sh`, stopped by `stop_dashboard.sh`; `SKIP_TUNNEL=1` - to disable). PID/log: `/tmp/recounter_tunnel.pid` / `.log`. -- SSH key: .93's `~/.ssh/id_ed25519` is already installed in - `.96:~/.ssh/authorized_keys` (password auth to .96 works too — - `jetson/jetson`, same default FCP's `deploy_to_jetson.py` uses). -- Health check from FCP side: - `curl -m 5 -o /dev/null -w '%{http_code}' http://127.0.0.1:9050/api/models` - → expect `200`. -- **If tunnel is down**, recounter API is only reachable from .93 itself. - FCP will get connection-refused → show "recounter tidak terhubung" and - retry, not an OCR-style error. - ## 2. Environment / URLs (given by operator) ``` @@ -119,7 +94,7 @@ MOTIONEYE_CAMERA_ID=2 Suggested new FCP env (`.env`, read like the other motioneye vars): ``` -RECOUNTER_URL=http://127.0.0.1:9050 # via reverse tunnel (see §1b) — NOT .93 +RECOUNTER_URL=http://localhost:9050 # http://192.168.192.96:9050 from other hosts RECOUNTER_API_KEY= # must equal recounter's RECOUNTER_API_KEY ``` diff --git a/start_dashboard.sh b/start_dashboard.sh index b9cded4..588081b 100755 --- a/start_dashboard.sh +++ b/start_dashboard.sh @@ -13,9 +13,3 @@ nohup python app.py > "$LOG" 2>&1 & sleep 1 echo "Started. PID $(pgrep -f 'python app.py'). Log: $LOG" echo "Open http://localhost:${WEB_PORT:-9050}" - -# Best-effort reverse tunnel so FCP (.96) can reach us at 127.0.0.1:9050 -# (see start_tunnel.sh header for the why). Dashboard is up either way. -if [ -x ./start_tunnel.sh ] && [ "${SKIP_TUNNEL:-0}" != "1" ]; then - ./start_tunnel.sh || echo "WARN: tunnel failed (FCP can't reach recounter yet) — see /tmp/recounter_tunnel.log" >&2 -fi diff --git a/start_tunnel.sh b/start_tunnel.sh deleted file mode 100755 index eae663b..0000000 --- a/start_tunnel.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Reverse SSH tunnel: publish THIS host's recounter :9050 as 127.0.0.1:9050 on .96. -# -# Why: .96 (FCP) cannot initiate connections to .93 (firewall drops inbound), -# but .93 → .96 outbound works. So .93 dials OUT to .96 and asks sshd there -# to listen on 9050, forwarding back through the tunnel to this host. -# FCP then calls http://127.0.0.1:9050/api/analyze — same IP as .96 — while -# counting runs on .93's hardware. -# -# FCP .env: RECOUNTER_URL=http://127.0.0.1:9050 -set -euo pipefail - -REMOTE_HOST="${RECOUNTER_TUNNEL_HOST:-192.168.192.96}" -REMOTE_USER="${RECOUNTER_TUNNEL_USER:-jetson}" -REMOTE_PORT="${RECOUNTER_TUNNEL_PORT:-9050}" # listen port on .96 -LOCAL_PORT="${WEB_PORT:-9050}" # recounter on this host -PIDFILE=/tmp/recounter_tunnel.pid - -pgrep -f "ssh.*-R ${REMOTE_PORT}:127.0.0.1:${LOCAL_PORT}" > /dev/null && { - echo "Tunnel already running (pid $(pgrep -f "ssh.*-R ${REMOTE_PORT}:127.0.0.1:${LOCAL_PORT}" | tr '\n' ' '))" - exit 0 -} - -nohup ssh -N \ - -o ServerAliveInterval=30 \ - -o ServerAliveCountMax=3 \ - -o ExitOnForwardFailure=yes \ - -o StrictHostKeyChecking=accept-new \ - -R "127.0.0.1:${REMOTE_PORT}:127.0.0.1:${LOCAL_PORT}" \ - "${REMOTE_USER}@${REMOTE_HOST}" \ - > /tmp/recounter_tunnel.log 2>&1 & -echo $! > "$PIDFILE" -sleep 1 - -if kill -0 "$(cat "$PIDFILE")" 2>/dev/null; then - echo "Tunnel up: ${REMOTE_HOST}:${REMOTE_PORT} -> 127.0.0.1:${LOCAL_PORT} (pid $(cat "$PIDFILE"))" -else - echo "Tunnel FAILED — see /tmp/recounter_tunnel.log" >&2 - cat /tmp/recounter_tunnel.log >&2 - exit 1 -fi diff --git a/stop_dashboard.sh b/stop_dashboard.sh index 166b0fa..55873ca 100755 --- a/stop_dashboard.sh +++ b/stop_dashboard.sh @@ -16,7 +16,3 @@ if pgrep -f "python app.py" > /dev/null; then else echo "Stopped." fi - -# Tunnel is useless without the web UI behind it (best-effort). -[ -x "$(dirname "$0")/stop_tunnel.sh" ] && "$(dirname "$0")/stop_tunnel.sh" || true -exit 0 diff --git a/stop_tunnel.sh b/stop_tunnel.sh deleted file mode 100755 index 8d37c64..0000000 --- a/stop_tunnel.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash -# Stop the reverse SSH tunnel started by start_tunnel.sh. -set -euo pipefail -PIDS=$(pgrep -f "ssh.*-R .*127.0.0.1:9050" || true) -if [ -z "$PIDS" ]; then - echo "No tunnel running." - exit 0 -fi -kill $PIDS -echo "Stopped tunnel (pid $PIDS)."