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

64 lines
1.9 KiB
Python

#!/usr/bin/env python3
from __future__ import annotations
import json
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def ssh(host, port, user, pw):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(host, port, user, pw, timeout=45, banner_timeout=120, allow_agent=False, look_for_keys=False)
return c
def run(c, cmd, t=60):
_i, o, e = c.exec_command(cmd, timeout=t)
o.channel.recv_exit_status()
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
v = ssh("107.173.30.245", 22, "root", "Xiao4669805")
# restore: stop neko-3 if we started it during probe (was Exited before)
run(
v,
r"""
set +e
# only stop if it was our accidental start; leave others alone
docker stop douyinweb-neko-3 >/dev/null 2>&1
docker ps -a --filter name='^douyinweb-neko-' --format '{{.Names}} {{.Status}}' | head -20
echo '--- prefer fields ---'
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/assign/groups | python3 -c '
import sys,json
d=json.load(sys.stdin)
rows=d if isinstance(d,list) else d.get("groups") or []
for g in rows:
print({
"name": (g.get("name") or "")[:28],
"prefer": g.get("neko_open_prefer"),
"src": g.get("neko_open_source"),
"open": (g.get("neko_open_url") or "")[:70],
"local": (g.get("neko_local_studio_url") or "")[:50],
"ops": (g.get("ops_neko_open_url") or "")[:50],
"neko_en": g.get("neko_enabled"),
"local_id": g.get("neko_instance_id"),
"ops_slot": g.get("ops_neko_slot"),
})
'
rm -f "$CS"
echo '--- 127 vs 0.0.0.0 bind on 9202 ---'
ss -lntp | grep ':9202'
""",
)
v.close()
print("DONE")