File size: 1,767 Bytes
e9e9f83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env bash
# ─────────────────────────────────────────────────────────────────────────────
# XERO interface β€” remote launcher (token-gated, public bind).
# Author: Michael Laurence Curzi β€” ZEDEC AI / 36N9 Genetics LLC Β· MIT (Attrib.)
# Usage:  run_remote.sh [PORT]      (default 8893)
# Stops any existing server BY PORT (never by process name, so it can't match
# and kill the shell/SSH session that is running this script).
# ─────────────────────────────────────────────────────────────────────────────
set -u
PORT="${1:-8893}"
APP="$HOME/xero"
cd "$APP" || { echo "FATAL: $APP missing"; exit 1; }

# stop whatever is listening on PORT (port-based, name-agnostic)
pid="$(ss -ltnp 2>/dev/null | grep ":$PORT " | grep -oE 'pid=[0-9]+' | head -1 | cut -d= -f2)"
if [ -n "${pid:-}" ]; then kill "$pid" 2>/dev/null || true; sleep 1; fi

TOKEN="$(cat "$HOME/.xero/chat_token" 2>/dev/null || true)"
export XERO_CHAT_TOKEN="$TOKEN"
export PYTHONPATH=modules

nohup setsid python3 serve/xero_chat_server.py --host 0.0.0.0 --port "$PORT" \
  > "$APP/server.log" 2>&1 < /dev/null &

sleep 3
echo "pids:   $(pgrep -f 'serve/xero_chat_server.py' | paste -sd, - || echo none)"
echo "listen: $(ss -ltn 2>/dev/null | grep ":$PORT " || echo NONE)"
echo "auth:   $([ -n "$TOKEN" ] && echo on || echo OFF)"
echo "health: $(curl -s -m 6 "http://127.0.0.1:$PORT/api/health" || echo FAIL)"
echo "--- server.log (tail) ---"
tail -n 15 "$APP/server.log" 2>/dev/null