[object Object]

← back to Pm2 Migration

snapshot — gitify backup 2026-05-19

a844ddeddcb404353ccc60b79124013dc001f48c · 2026-05-19 11:35:48 -0700 · Steve

Files touched

Diff

commit a844ddeddcb404353ccc60b79124013dc001f48c
Author: Steve <steve@designerwallcoverings.com>
Date:   Tue May 19 11:35:48 2026 -0700

    snapshot — gitify backup 2026-05-19
---
 start-tunnels.sh | 59 +++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 52 insertions(+), 7 deletions(-)

diff --git a/start-tunnels.sh b/start-tunnels.sh
index 88daa08..2c971ff 100755
--- a/start-tunnels.sh
+++ b/start-tunnels.sh
@@ -8,20 +8,65 @@
 # Local ports avoid collision with the user's existing local postgres on 5432.
 # Migrated agents have their connection strings rewritten to point here.
 
+set -u
+
 KAMATERA_USER="${KAMATERA_USER:-root}"
 KAMATERA_HOST="${KAMATERA_HOST:-45.61.58.125}"
+LOCAL_PG_PORT="${LOCAL_PG_PORT:-15432}"
+LOCAL_REDIS_PORT="${LOCAL_REDIS_PORT:-16379}"
+
+# Pre-exec orphan cleanup — kill stray ssh forwarders to the same host that
+# aren't parented by a live autossh. Stops the "bind: Address already in use"
+# loop that happens after a network blip when the previous ssh hasn't released
+# its local sockets yet.
+own_pid=$$
+for pid in $(pgrep -f "ssh.*${KAMATERA_HOST}" 2>/dev/null || true); do
+  [ "$pid" = "$own_pid" ] && continue
+  parent=$(ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ')
+  [ -z "$parent" ] && continue
+  pcomm=$(ps -o comm= -p "$parent" 2>/dev/null | xargs)
+  case "$pcomm" in
+    */autossh|autossh) continue ;;
+  esac
+  echo "[start-tunnels] killing orphan ssh pid=$pid (parent comm=$pcomm)" >&2
+  kill "$pid" 2>/dev/null || true
+done
+sleep 1
 
-# Check responsiveness every 30s; restart tunnel if dead.
+# autossh tuning — quieter logs, faster dead-peer detection.
 export AUTOSSH_POLL=30
-export AUTOSSH_GATETIME=0   # don't wait for first successful connection
-export AUTOSSH_LOGLEVEL=4
+export AUTOSSH_GATETIME=0          # don't wait for first successful connection
+export AUTOSSH_LOGLEVEL=1          # errors only (was 4 = verbose — log spam source)
 export AUTOSSH_LOGFILE=/Users/stevestudio2/.pm2/logs/kamatera-tunnels.log
+export AUTOSSH_MAXLIFETIME=43200   # recycle after 12h to clear lingering sockets
+
+# Dedup repeated identical stderr lines (port-bind / timeout spam during outages)
+# into "(repeated N times)" summaries. autossh's own log captures reconnect detail.
+dedup_stderr() {
+  awk '
+    { fflush() }
+    $0 == last { count++; next }
+    {
+      if (count > 1) print "(... previous line repeated " count " times)" > "/dev/stderr"
+      print > "/dev/stderr"
+      last = $0
+      count = 1
+    }
+    END {
+      if (count > 1) print "(... previous line repeated " count " times)" > "/dev/stderr"
+    }
+  '
+}
 
+# ServerAliveCountMax lowered 3→2 (60s vs 90s dead-detection), ConnectTimeout
+# added to fail fast on network drops.
 exec autossh -M 0 -N \
   -o ServerAliveInterval=30 \
-  -o ServerAliveCountMax=3 \
+  -o ServerAliveCountMax=2 \
   -o ExitOnForwardFailure=yes \
   -o StrictHostKeyChecking=no \
-  -L 15432:127.0.0.1:5432 \
-  -L 16379:127.0.0.1:6379 \
-  "$KAMATERA_USER@$KAMATERA_HOST"
+  -o ConnectTimeout=15 \
+  -L "${LOCAL_PG_PORT}:127.0.0.1:5432" \
+  -L "${LOCAL_REDIS_PORT}:127.0.0.1:6379" \
+  "${KAMATERA_USER}@${KAMATERA_HOST}" \
+  2> >(dedup_stderr)

← 06e64fa initial scaffold (gitify-all 2026-05-06)  ·  back to Pm2 Migration  ·  broaden .gitignore to cover *.bak.* and *.pre-* snapshot fil 4015728 →