96 lines
3.4 KiB
Python
96 lines
3.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Align dy douyinweb-api bind with dylive (0.0.0.0:8014). Do not touch dylive."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
HOST = "108.174.50.68"
|
|
PASS = "Xiao4669805"
|
|
|
|
|
|
def main():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
c.connect(HOST, 22, "root", PASS, timeout=30, allow_agent=False, look_for_keys=False)
|
|
break
|
|
except Exception as e:
|
|
print(e, flush=True)
|
|
time.sleep(1 + i)
|
|
else:
|
|
raise SystemExit("ssh_fail")
|
|
|
|
cmd = r"""
|
|
set -e
|
|
UNIT=/etc/systemd/system/douyinweb-api.service
|
|
cp -a "$UNIT" "${UNIT}.bak_bind_$(date +%Y%m%d%H%M%S)"
|
|
echo '--- before ---'
|
|
grep ExecStart "$UNIT"
|
|
# only change host bind; keep everything else
|
|
sed -i 's|--host 127\.0\.0\.1 --port 8014|--host 0.0.0.0 --port 8014|g' "$UNIT"
|
|
echo '--- after ---'
|
|
grep ExecStart "$UNIT"
|
|
systemctl daemon-reload
|
|
systemctl restart douyinweb-api
|
|
sleep 3
|
|
echo api=$(systemctl is-active douyinweb-api)
|
|
ss -lntp | grep 8014 || true
|
|
NAME=$(docker ps --filter name=douyinweb-neko --format '{{.Names}}' | head -1)
|
|
echo CONTAINER=$NAME
|
|
echo -n 'host.docker.internal -> '
|
|
docker exec "$NAME" curl -sS -m 4 -o /dev/null -w '%{http_code}' http://host.docker.internal:8014/api/health || echo fail
|
|
echo
|
|
echo -n '172.17.0.1 -> '
|
|
docker exec "$NAME" curl -sS -m 4 -o /dev/null -w '%{http_code}' http://172.17.0.1:8014/api/health || echo fail
|
|
echo
|
|
echo -n 'gateway via host-gateway IP -> '
|
|
GW=$(docker inspect "$NAME" --format '{{range .NetworkSettings.Networks}}{{.Gateway}}{{end}}')
|
|
echo -n "GW=$GW "
|
|
docker exec "$NAME" curl -sS -m 4 -o /dev/null -w '%{http_code}' "http://${GW}:8014/api/health" || echo fail
|
|
echo
|
|
# force one CDP + wait a bit for extension if Live page open
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
import json, time
|
|
from app import youtube_neko, yt_assign_db
|
|
print('poll_ids', youtube_neko._neko_ids_for_cdp_poll())
|
|
print('poll', json.dumps(youtube_neko.poll_studio_cdp_once(), ensure_ascii=False)[:500])
|
|
time.sleep(8)
|
|
# check recent ingest via journal is done outside
|
|
for g in yt_assign_db.list_groups(include_urls=False):
|
|
if int(g.get('neko_instance_id') or 0)==6:
|
|
snap=youtube_neko.studio_snapshot_for_group(g, max_age_sec=120)
|
|
print('SNAP', g.get('name'), {k:snap.get(k) for k in ('live_page_open','on_air','viewer_count','total_views','detect_source','url')})
|
|
PY
|
|
journalctl -u douyinweb-api --since '2 min ago' --no-pager | grep -c 'live/ingest' || true
|
|
journalctl -u douyinweb-api --since '2 min ago' --no-pager | grep 'live/ingest' | tail -5
|
|
"""
|
|
_i, o, e = c.exec_command(cmd, timeout=120, get_pty=True)
|
|
chan = o.channel
|
|
t0 = time.time()
|
|
while True:
|
|
if chan.recv_ready():
|
|
sys.stdout.write(chan.recv(8192).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
if chan.exit_status_ready():
|
|
while chan.recv_ready():
|
|
sys.stdout.write(chan.recv(8192).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
break
|
|
if time.time() - t0 > 110:
|
|
print("TIMEOUT", flush=True)
|
|
break
|
|
time.sleep(0.12)
|
|
print("\n[exit", chan.recv_exit_status(), "]", flush=True)
|
|
c.close()
|
|
print("DY_BIND_ALIGNED", flush=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|