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

95 lines
3.5 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Why VPS local Nekos show Chrome when they should be stopped by default."""
import json
import sys
import httpx
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
remote = r"""
echo '=== docker assign nekos ==='
docker ps -a --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}' | grep -E 'NAMES|douyinweb-neko-' | head -40
echo '=== who owns 920x ==='
ss -lntp | grep -E ':920[0-9]' | head -20
echo '=== ssh tunnels? ==='
ps aux | grep -E '920[0-9]|neko|frp' | grep -v grep | head -30
echo '=== host profile / settings ==='
cd /opt/douyinWEB/backend
PY=python3; [ -x .venv/bin/python ] && PY=.venv/bin/python
$PY - <<'PY'
import sqlite3, json
from pathlib import Path
db=Path('data/monitor.db')
con=sqlite3.connect(f'file:{db}?mode=ro', uri=True)
con.row_factory=sqlite3.Row
cur=con.cursor()
# kv settings related
for k in ('host_profile','youtube_relay_exclusive_live','youtube_relay_enabled'):
try:
r=cur.execute("select value from kv_settings where key=?", (k,)).fetchone()
print('kv', k, r['value'] if r else None)
except Exception as e:
# maybe different schema
pass
try:
rows=cur.execute("select key, value from kv_settings where key like '%host%' or key like '%neko%' or key like '%exclusive%' or key like '%relay_enabled%'").fetchall()
for r in rows:
print('set', r['key'], str(r['value'])[:80])
except Exception as e:
print('kv_err', e)
# try settings table
try:
rows=cur.execute("select key, value from settings where key like '%host%' or key like '%neko%' or key like '%exclusive%' or key like '%relay%'").fetchall()
for r in rows: print('set2', r[0], str(r[1])[:80])
except Exception as e2:
print('set2_err', e2)
rows=cur.execute("select name, neko_instance_id, neko_enabled, category from yt_assign_groups order by neko_instance_id").fetchall()
print('=== groups neko_enabled ===')
for r in rows:
print(dict(r))
con.close()
PY
"""
sftp = c.open_sftp()
with sftp.file("/tmp/_diag_vps_neko_default.sh", "wb") as f:
f.write(remote.encode())
sftp.close()
_i, o, e = c.exec_command("bash /tmp/_diag_vps_neko_default.sh", timeout=90)
print((o.read() + e.read()).decode("utf-8", "replace"))
# API status
client = httpx.Client(base_url="https://dylive.nomadro.com", timeout=40, follow_redirects=True)
r = client.post("/api/auth/login", json={"username": "hackrobot", "password": "Xiao4669805@"})
print("login", r.status_code)
st = client.get("/api/youtube/neko/status").json()
print("neko status available", st.get("available"), "count", len(st.get("instances") or []))
for inst in (st.get("instances") or [])[:12]:
print(
json.dumps(
{
"id": inst.get("id"),
"running": inst.get("running"),
"ready": inst.get("ready"),
"status": inst.get("status"),
"studio_url": (inst.get("studio_url") or "")[:60],
},
ensure_ascii=False,
)
)
hp = client.get("/api/ops/host-profile").json()
print("host_profile", json.dumps(hp, ensure_ascii=False)[:500])
client.close()
c.close()
if __name__ == "__main__":
main()