131 lines
4.2 KiB
Python
131 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Finish dylive local neko after port remap (wait for API)."""
|
|
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,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
return c
|
|
|
|
|
|
def run(c, cmd, t=180):
|
|
print(f"\n$ {cmd[:180]}", 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[-10000:] if len(out) > 10000 else out, flush=True)
|
|
return code, out
|
|
|
|
|
|
c = ssh()
|
|
run(
|
|
c,
|
|
r"""
|
|
set +e
|
|
echo '--- units ---'
|
|
systemctl is-active dy-frp-http-aux caddy douyinweb-api douyinweb-web
|
|
echo '--- frp-aux forwards ---'
|
|
grep -oE '127.0.0.1:[0-9]+' /etc/systemd/system/dy-frp-http-aux.service | head -40
|
|
echo '--- caddy neko1 proxy ---'
|
|
grep -A2 'handle_path /neko/1/\*' /etc/caddy/sites/dy.nomadro.com.caddy | head -8
|
|
echo '--- who owns 9200/19200 ---'
|
|
ss -lntp | grep -E ':(920[0-7]|1920[0-7])\b' | head -20
|
|
echo '--- NAT1TO1 env ---'
|
|
systemctl show douyinweb-api -p Environment --value | tr ' ' '\n' | grep NEKO
|
|
# wait api
|
|
for i in $(seq 1 30); do
|
|
curl -sS -m 2 http://127.0.0.1:8014/api/health >/dev/null 2>&1 && echo api_up_$i && break
|
|
sleep 1
|
|
done
|
|
curl -sS -m 8 http://127.0.0.1:8014/api/health | head -c 200; echo
|
|
# ensure host_profile deployed
|
|
python3 -c 'from app import host_profile; print(host_profile.status()["effects"]["vps"])' 2>/dev/null || \
|
|
(cd /opt/douyinWEB/backend && /opt/douyinWEB/.venv/bin/python -c 'import sys; sys.path.insert(0,"."); from app import host_profile; print(host_profile.status()["effects"]["vps"])')
|
|
""",
|
|
90,
|
|
)
|
|
|
|
run(
|
|
c,
|
|
r"""
|
|
set +e
|
|
# if api down, restart
|
|
systemctl is-active douyinweb-api || systemctl restart douyinweb-api
|
|
sleep 2
|
|
for i in $(seq 1 40); do
|
|
curl -sS -m 2 http://127.0.0.1:8014/api/health >/dev/null 2>&1 && break
|
|
sleep 1
|
|
done
|
|
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@"}'
|
|
echo
|
|
GID=$(curl -sS -m 20 -b "$CS" http://127.0.0.1:8014/api/youtube/assign/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 int(g.get("neko_instance_id") or 0)==3:
|
|
print(g.get("id") or ""); break
|
|
')
|
|
echo gid=$GID
|
|
curl -sS -m 180 -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}' | tee /tmp/neko_start3.json | python3 -c '
|
|
import sys,json
|
|
d=json.load(sys.stdin)
|
|
print("keys", list(d)[:12])
|
|
n=d.get("neko") or {}
|
|
print("neko", {k:n.get(k) for k in ("id","running","ready","status","studio_url","detail")})
|
|
g=d.get("group") or {}
|
|
print("enabled", g.get("neko_enabled"), "err", d.get("detail") or d.get("error"))
|
|
'
|
|
sleep 3
|
|
docker ps --format '{{.Names}} {{.Status}}' | grep douyinweb-neko | head
|
|
ss -lntp | grep -E ':(9202|19200)\b' | head
|
|
curl -sS -m 10 -o /dev/null -w 'local9202=%{http_code}\n' http://127.0.0.1:9202/
|
|
curl -sS -m 10 -o /dev/null -w 'aux19200=%{http_code}\n' http://127.0.0.1:19200/
|
|
docker inspect douyinweb-neko-3 --format '{{json .Config.Env}}' 2>/dev/null | tr ',' '\n' | grep -E 'NAT1TO1|BITRATE|MAX_FPS|DESKTOP_SCREEN|BROWSER_PROXY|START_URL' || echo no_container
|
|
rm -f "$CS"
|
|
""",
|
|
220,
|
|
)
|
|
c.close()
|
|
|
|
print("\n===== public =====", flush=True)
|
|
with httpx.Client(follow_redirects=False, timeout=25) as cl:
|
|
for u in [
|
|
"https://dylive.nomadro.com/api/health",
|
|
"https://dylive.nomadro.com/neko/3/",
|
|
"https://dy.nomadro.com/api/health",
|
|
"https://dy.nomadro.com/neko/1/",
|
|
"https://dy.nomadro.cn/neko/1/",
|
|
"https://dy.nomadro.cn/ops-neko/1/",
|
|
]:
|
|
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)
|