douyinWEB/scripts/_audit_dual_fleet_health.py
2026-09-13 22:10:49 -05:00

119 lines
4.6 KiB
Python

#!/usr/bin/env python3
"""Fleet self-check: dy + dylive neko chrome, mounts, API. Never recreate Neko."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOSTS = [
("dylive", "107.173.30.245"),
("dy", "108.174.50.68"),
]
def connect(host: str):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
host,
22,
"root",
"Xiao4669805",
timeout=40,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
return c
except Exception as e:
print(f"ssh_retry {host} {i}: {e}", flush=True)
time.sleep(2 + i)
raise SystemExit(f"ssh_fail {host}")
SCRIPT = r"""
set +e
echo '=== host ==='
hostname; free -m | head -2; uptime
systemctl is-active douyinweb-api douyinweb-web 2>/dev/null
curl -sS -m 8 -o /dev/null -w 'api_health:%{http_code}\n' http://127.0.0.1:8014/api/health
curl -sS -m 8 -o /dev/null -w 'fe_youtube:%{http_code}\n' http://127.0.0.1:4015/youtube
echo '=== browser-launch host ==='
file /opt/douyinWEB/backend/neko/browser-launch.sh 2>/dev/null || ls -la /opt/douyinWEB/backend/neko/browser-launch.sh
head -1 /opt/douyinWEB/backend/neko/browser-launch.sh | od -c | head -2
grep -n 'jitless\|no-turbofan\|PassageEmbeddings\|no-wasm-simd' /opt/douyinWEB/backend/neko/browser-launch.sh | head -10
sh -n /opt/douyinWEB/backend/neko/browser-launch.sh && echo launch_syntax_ok || echo launch_syntax_BAD
echo '=== neko containers ==='
docker ps -a --filter name=douyinweb-neko --format '{{.Names}} {{.Status}}' | sort -V
echo '=== running neko chrome/supervisor ==='
for n in $(docker ps --filter name=douyinweb-neko --format '{{.Names}}' | sort -V); do
echo "--- $n ---"
# deleted mount?
del=$(docker exec "$n" sh -c 'cat /proc/self/mountinfo 2>/dev/null | grep browser-launch' | grep -c '//deleted' || true)
echo "browser_launch_deleted_mount=$del"
docker exec "$n" sh -c 'grep -n jitless /etc/neko/browser-launch.sh 2>/dev/null | head -1; sh -n /etc/neko/browser-launch.sh 2>/dev/null && echo syntax_ok || echo syntax_BAD'
st=$(docker exec "$n" supervisorctl status google-chrome 2>/dev/null | head -1)
echo "chrome: $st"
cdp=$(docker exec "$n" sh -c 'curl -sS -m 2 http://127.0.0.1:9222/json/version 2>/dev/null' | head -c 80)
echo "cdp: ${cdp:-FAIL}"
done
echo '=== assign neko_enabled vs running ==='
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
from app import yt_assign_db, db
cfg = db.get_settings_map()
print('auto', bool(cfg.get('youtube_relay_enabled') or cfg.get('youtube_relay_auto')))
# try common keys
for k in ('youtube_relay_enabled','youtube_relay_pipeline_enabled','youtube_relay_auto_push'):
if k in cfg: print(k, cfg.get(k))
print('time_slot', cfg.get('youtube_relay_time_slot_mode'))
print('exclusive', cfg.get('youtube_relay_exclusive_live'))
en=[]
for g in yt_assign_db.list_groups(include_urls=False, include_secret=False):
nid=int(g.get('neko_instance_id') or 0)
if g.get('neko_enabled'):
en.append((g.get('name'), nid, g.get('category')))
print('neko_enabled', en)
PY
echo '=== relay status snippet ==='
CS=$(mktemp)
curl -sS -m 15 -c "$CS" -b "$CS" -X POST http://127.0.0.1:8014/api/auth/login \
-H 'Content-Type: application/json' \
-d '{"username":"hackrobot","password":"Xiao4669805@"}' >/dev/null
curl -sS -m 15 -b "$CS" http://127.0.0.1:8014/api/youtube/relay/status | python3 - <<'PY'
import sys,json
d=json.load(sys.stdin)
print('enabled', d.get('enabled'), 'running', d.get('running'), 'pushing', d.get('pushing_count'))
print('douyin_live', d.get('douyin_live_count'), 'winner', d.get('exclusive_winner_group_id'))
s=d.get('settings') or {}
print('slot', s.get('youtube_relay_time_slot_mode'), 'excl', s.get('youtube_relay_exclusive_live'))
print('err', (d.get('last_error') or '')[:200])
PY
echo '=== FE marker ==='
grep -Rnl '普通频道 · 在播抖音' /opt/douyinWEB/frontend/src/components/YtAssignPanel.tsx 2>/dev/null | head -1
grep -Rnl '普通频道 · 在播抖音' /opt/douyinWEB/frontend/.next/static 2>/dev/null | head -2 || echo 'marker_not_in_static_or_missing_build'
echo HOST_CHECK_DONE
"""
for label, host in HOSTS:
print(f"\n######## {label} {host} ########", flush=True)
c = connect(host)
_i, o, e = c.exec_command(SCRIPT, timeout=240)
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
c.close()
print("ALL_HOSTS_DONE", flush=True)