Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
100 lines
3.3 KiB
Python
100 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Diagnose neko/7 with sudo docker — no Chrome restart."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
PASS = "4669805"
|
|
NAME = "douyinweb-neko-7"
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(10):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=45,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
break
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2)
|
|
else:
|
|
return 1
|
|
|
|
sh = f"""echo '{PASS}' | sudo -S -p '' bash -lc '
|
|
set -e
|
|
NAME={NAME}
|
|
echo === container ===
|
|
docker ps -a --filter name=$NAME --format "{{{{.Names}}}} {{{{.Status}}}}"
|
|
docker inspect $NAME --format "Restart={{{{.RestartCount}}}} OOM={{{{.State.OOMKilled}}}} Health={{{{json .State.Health.Status}}}}" 2>/dev/null || true
|
|
curl -sS -m 5 -o /dev/null -w "http9206:%{{http_code}}\\n" http://127.0.0.1:9206/ || true
|
|
|
|
echo === supervisor ===
|
|
docker exec $NAME supervisorctl status || true
|
|
|
|
echo === chrome procs ===
|
|
docker exec $NAME bash -lc "ps aux | grep -E \\"[c]hrome|[c]hromium\\" | head -25; free -m | head -2"
|
|
|
|
echo === CDP tabs ===
|
|
docker exec $NAME python3 - <<'"'"'PY'"'"'
|
|
import json,urllib.request
|
|
try:
|
|
tabs=json.loads(urllib.request.urlopen("http://127.0.0.1:9222/json/list",timeout=5).read().decode())
|
|
except Exception as e:
|
|
print("CDP_FAIL", e); raise SystemExit(0)
|
|
print("tab_count", len(tabs))
|
|
for t in tabs:
|
|
print("-", (t.get("type") or ""), "|", (t.get("title") or "")[:70], "|", (t.get("url") or "")[:140])
|
|
PY
|
|
|
|
echo === scrape ===
|
|
python3 - <<'"'"'PY'"'"'
|
|
import subprocess
|
|
from pathlib import Path
|
|
script = Path("/opt/douyinWEB/backend/neko/cdp_studio_scrape.py").read_text(encoding="utf-8")
|
|
p = subprocess.run(["docker","exec","-i","{NAME}","python3","-"], input=script, capture_output=True, text=True, timeout=35)
|
|
print(((p.stdout or "") + (p.stderr or ""))[-1200:])
|
|
PY
|
|
|
|
echo === logs ===
|
|
docker logs --tail 40 $NAME 2>&1 | tail -40
|
|
|
|
echo === chrome log ===
|
|
docker exec $NAME bash -lc "ls /var/log/supervisor 2>/dev/null; tail -50 /var/log/supervisor/*chrome* 2>/dev/null || tail -50 /var/log/supervisor/*chromium* 2>/dev/null || echo none"
|
|
|
|
echo === studio lookup ===
|
|
cd /opt/douyinWEB/backend
|
|
PYTHONPATH=/opt/douyinWEB/backend .venv/bin/python - <<'"'"'PY'"'"'
|
|
from app import yt_assign_db, youtube_neko as yn
|
|
for g in yt_assign_db.list_groups(include_urls=False):
|
|
if int(g.get("neko_instance_id") or 0) == 7:
|
|
print("group", g.get("name"), "enabled", g.get("neko_enabled"), "studio", (g.get("neko_studio_url") or "")[:120])
|
|
st = yn._container_state(7, check_http=True)
|
|
print("state", st)
|
|
snap = yn.studio_on_air_lookup(7, max_age_sec=180)
|
|
print({{k: snap.get(k) for k in ("live_page_open","on_air","live_status","health","viewer_count","total_views","live_duration","url","detect_source")}})
|
|
PY
|
|
echo DIAG_OK
|
|
'"""
|
|
_, o, e = c.exec_command(sh, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|