xero-bio-genesis / serve /run_remote.sh
transmutationist's picture
XERO: card + code + docs (WIP; see STATUS_AND_AUDIT.md)
e9e9f83 verified
Raw History Blame Contribute Delete
1.77 kB
#!/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