106 lines
3.1 KiB
Python
106 lines
3.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Force-recreate dylive assign Neko containers so :920x publish correctly."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import httpx
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def ssh():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
"107.173.30.245",
|
|
22,
|
|
"root",
|
|
"Xiao4669805",
|
|
timeout=45,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, t=300):
|
|
print(f"\n$ {cmd[:200]}", flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=t)
|
|
code = o.channel.recv_exit_status()
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-14000:] if len(out) > 14000 else out, flush=True)
|
|
return code, out
|
|
|
|
|
|
c = ssh()
|
|
run(
|
|
c,
|
|
r"""
|
|
set +e
|
|
cd /opt/douyinWEB/backend/data/neko
|
|
# Stop/remove stale containers that lack published ports
|
|
for id in 3 7 8; do
|
|
docker rm -f douyinweb-neko-$id 2>/dev/null
|
|
done
|
|
# Recreate via API start (writes compose + up) for enabled groups
|
|
CS=$(mktemp)
|
|
curl -sS -m 20 -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
|
|
python3 - <<'PY'
|
|
import json,urllib.request
|
|
cs=open('/tmp/neko_cookie.txt','w')
|
|
PY
|
|
# simpler: use curl cookie jar
|
|
GROUPS=$(curl -sS -m 20 -b "$CS" http://127.0.0.1:8014/api/youtube/assign/groups)
|
|
echo "$GROUPS" | python3 -c '
|
|
import sys,json
|
|
rows=json.load(sys.stdin)
|
|
rows=rows if isinstance(rows,list) else rows.get("groups") or []
|
|
for g in rows:
|
|
if g.get("neko_enabled") and int(g.get("neko_instance_id") or 0)>0:
|
|
print(g["id"], int(g["neko_instance_id"]), (g.get("name") or "")[:30])
|
|
' > /tmp/neko_enabled_groups.txt
|
|
cat /tmp/neko_enabled_groups.txt
|
|
while read -r GID NID NAME; do
|
|
echo "START $NID $NAME"
|
|
curl -sS -m 240 -b "$CS" -X POST "http://127.0.0.1:8014/api/youtube/assign/groups/${GID}/neko" \
|
|
-H 'Content-Type: application/json' \
|
|
-d '{"action":"start","enabled":true,"force_recreate":true}' | python3 -c '
|
|
import sys,json
|
|
d=json.load(sys.stdin)
|
|
n=d.get("neko") or {}
|
|
print(" ->", n.get("status"), "running", n.get("running"), "ready", n.get("ready"), "studio", n.get("studio_url"), "err", d.get("detail") or d.get("error") or "")
|
|
'
|
|
done < /tmp/neko_enabled_groups.txt
|
|
sleep 3
|
|
echo '--- docker ports ---'
|
|
docker ps --format '{{.Names}} {{.Status}} {{.Ports}}' | grep douyinweb-neko
|
|
echo '--- ss 920 ---'
|
|
ss -lntp | grep -E ':(920[0-7])\b' | head
|
|
for p in 9200 9202 9206; do
|
|
curl -sS -m 5 -o /dev/null -w "p$p=%{http_code}\n" http://127.0.0.1:$p/ || echo p$p=fail
|
|
done
|
|
rm -f "$CS"
|
|
""",
|
|
300,
|
|
)
|
|
c.close()
|
|
|
|
with httpx.Client(follow_redirects=False, timeout=25) as cl:
|
|
for u in [
|
|
"https://dylive.nomadro.com/neko/3/",
|
|
"https://dylive.nomadro.com/neko/7/",
|
|
"https://dy.nomadro.com/neko/1/",
|
|
"https://dylive.nomadro.com/api/health",
|
|
]:
|
|
try:
|
|
r = cl.get(u)
|
|
print(f"{r.status_code} {u}", flush=True)
|
|
except Exception as ex:
|
|
print(f"ERR {u} {ex}", flush=True)
|
|
print("DONE", flush=True)
|