aiden-duplex / scripts /check_server.sh
sadmN's picture
Add scripts/check_server.sh (one-command health check)
61012f7 verified
Raw History Blame Contribute Delete
3.8 kB
#!/usr/bin/env bash
# Check a running Aiden server. Run it in a second terminal after starting run.sh:
# bash scripts/check_server.sh
# Optional: PORT=8999 HOST=0.0.0.0 bash scripts/check_server.sh
set -uo pipefail
ROOT=$(cd "$(dirname "$0")/.." && pwd)
HOST=${HOST:-127.0.0.1}
PORT=${PORT:-8998}
BASE="http://$HOST:$PORT"
FAIL=0
report() { printf '%-34s %s\n' "$1" "$2"; }
# 1. Is anything listening on the port?
if ss -lnt 2>/dev/null | grep -q ":$PORT "; then
report "listening on port $PORT" "PASS"
else
report "listening on port $PORT" "FAIL - server is not running (see the run.sh terminal)"
FAIL=1
fi
# 2. Health endpoint: ready means thinker + ASR + TTS workers are alive.
HEALTH=$(curl -fsS --max-time 5 "$BASE/health" 2>/dev/null)
case "$HEALTH" in
*'"ready": true'*|*'"ready":true'*)
report "health endpoint" "PASS ($HEALTH)" ;;
"")
report "health endpoint" "FAIL - no response from $BASE" ; FAIL=1 ;;
*)
report "health endpoint" "WAIT - still loading: $HEALTH" ; FAIL=1 ;;
esac
# 3. The demo page is served and contains the UI.
PAGE=$(mktemp)
CODE=$(curl -s -o "$PAGE" -w '%{http_code}' --max-time 5 "$BASE/" 2>/dev/null)
if [ "$CODE" = "200" ] && grep -q 'Enable mic' "$PAGE"; then
report "demo page" "PASS (HTTP 200)"
else
report "demo page" "FAIL (HTTP ${CODE:-none})"
FAIL=1
fi
rm -f "$PAGE"
# 4. GPU memory, for information only.
if command -v nvidia-smi >/dev/null 2>&1; then
report "GPU memory used" "$(nvidia-smi --query-gpu=memory.used,memory.total \
--format=csv,noheader 2>/dev/null | head -1)"
fi
# 5. One real turn over the same WebSocket the browser uses.
PY="$ROOT/.venv-thinker/bin/python"
[ -x "$PY" ] || PY=$(command -v python3 || true)
if [ -n "$PY" ]; then
if AIDEN_URL="ws://$HOST:$PORT/ws" "$PY" - <<'PY'
import asyncio, json, os, sys
import aiohttp
URL = os.environ['AIDEN_URL']
headers = {'Origin': os.environ['AIDEN_ORIGIN']} if os.environ.get('AIDEN_ORIGIN') else {}
async def main():
async with aiohttp.ClientSession() as s:
async with s.ws_connect(URL, headers=headers) as ws:
await ws.send_json({'type': 'text', 'text': 'look up the movie Obsession'})
tools, said = [], []
try:
while len(said) < 2:
m = await asyncio.wait_for(ws.receive(), 60)
if m.type != aiohttp.WSMsgType.TEXT:
continue
d = json.loads(m.data)
if d.get('type') == 'tool':
tools.append('%s %s' % (d.get('name'), d.get('stage')))
elif d.get('type') == 'audio':
said.append(d.get('text', ''))
await ws.send_json({'type': 'playing', 'seq': d['seq'],
'epoch': d['epoch']})
await ws.send_json({'type': 'played', 'seq': d['seq'],
'epoch': d['epoch']})
elif d.get('type') == 'error':
print('turn: FAIL - ' + str(d.get('message')))
return 1
except asyncio.TimeoutError:
print('turn: FAIL - no audio within 60 s')
return 1
print('turn: PASS - tools=%s' % (tools or ['none']))
print(' speech=%s' % (' '.join(said)[:120]))
return 0
sys.exit(asyncio.run(main()))
PY
then :; else FAIL=1; fi
else
report "one live turn" "SKIP - no python found"
fi
echo
if [ "$FAIL" = 0 ]; then
echo "RESULT: server is healthy. Open $BASE in a browser and click Enable mic."
else
echo "RESULT: not ready yet. Re-run this check in 30 s; if it still fails, read"
echo " the terminal where run.sh is running."
fi
exit "$FAIL"