#!/usr/bin/env python3 """Diagnose S3 / covers on dy + dylive. Read-only.""" from __future__ import annotations import json import ssl import sys import time import urllib.request import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") CTX = ssl.create_default_context() HOSTS = [ ("dylive", "107.173.30.245", "https://dylive.nomadro.com"), ("dy", "108.174.50.68", "https://dy.nomadro.live"), ] def connect(host: str): c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) for i in range(8): try: c.connect( host, 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False, banner_timeout=120, ) return c except Exception as e: print(f"ssh_retry {host} {i}: {e}", flush=True) time.sleep(2 + i) raise SystemExit(f"ssh_fail {host}") SCRIPT = r""" set +e echo '=== units ===' systemctl is-active douyinweb-api douyinweb-web 2>/dev/null systemctl is-active seaweedfs-filer seaweed-filer weed-filer 2>/dev/null systemctl list-units --type=service --all 2>/dev/null | grep -iE 'seaweed|weed|s3|minio' | head -20 echo echo '=== listen ports (s3/filer related) ===' ss -lntp 2>/dev/null | grep -E ':8333|:8888|:18888|:8334|:9000|:9001|:8080|:8014|:4015' | head -30 echo echo '=== env / settings (S3 keys redacted) ===' cd /opt/douyinWEB/backend 2>/dev/null || cd /opt/douyinWEB if [ -f .venv/bin/python ]; then ./.venv/bin/python - <<'PY' from app.config import settings import os keys = [ 's3_endpoint','s3_public_endpoint','s3_bucket','s3_region','s3_access_key','s3_secret_key', 'public_base_url','covers_dir','seaweed' ] for k in dir(settings): if any(x in k.lower() for x in ('s3','cover','public','seaweed','cdn')): v = getattr(settings, k, None) if k.lower().endswith('secret') or 'secret' in k.lower() or 'password' in k.lower() or 'key' in k.lower() and 'access' in k.lower(): sv = str(v or '') print(f'settings.{k}=', (sv[:4]+'***'+sv[-2:] if len(sv)>8 else ('***' if sv else ''))) else: print(f'settings.{k}=', v) # env for ek in sorted(os.environ): if any(x in ek.upper() for x in ('S3','SEAWEED','COVER','PUBLIC_BASE','AWS','MINIO')): val = os.environ[ek] if any(x in ek.upper() for x in ('SECRET','PASSWORD','KEY')) and 'PUBLIC' not in ek.upper(): print(f'env.{ek}=', (val[:4]+'***' if val else '')) else: print(f'env.{ek}=', val) PY fi echo echo '=== local covers dir ===' ls -la /opt/douyinWEB/backend/data/covers 2>/dev/null | head -15 find /opt/douyinWEB/backend/data/covers -type f 2>/dev/null | head -8 echo count_files=$(find /opt/douyinWEB/backend/data/covers -type f 2>/dev/null | wc -l) echo echo '=== sample DB cover urls ===' cd /opt/douyinWEB/backend ./.venv/bin/python - <<'PY' from app import db try: rows = db.list_sessions(limit=8) if hasattr(db,'list_sessions') else None except Exception as e: print('list_sessions err', e) rows = None # fallback raw sql from app.db import _connect, _lock with _lock: conn=_connect() try: cur=conn.execute("SELECT id, cover_url, cover_proxy_url, anchor_name FROM sessions WHERE cover_url IS NOT NULL AND cover_url!='' ORDER BY started_at DESC LIMIT 8") except Exception: cur=conn.execute("SELECT id, cover_url, anchor_name FROM sessions WHERE cover_url IS NOT NULL AND cover_url!='' ORDER BY rowid DESC LIMIT 8") for r in cur.fetchall(): print(dict(r) if hasattr(r,'keys') else r) try: cur2=conn.execute("SELECT key, substr(value,1,120) FROM settings WHERE key LIKE '%s3%' OR key LIKE '%cover%' OR key LIKE '%public%' OR key LIKE '%seaweed%' LIMIT 30") for r in cur2.fetchall(): print('setting_row', r[0], r[1]) except Exception as e: print('settings_scan', e) PY echo echo '=== local HTTP probes ===' curl -sS -m 5 -o /dev/null -w 'api_health:%{http_code}\n' http://127.0.0.1:8014/api/health # covers static curl -sS -m 5 -o /dev/null -w 'covers_root:%{http_code}\n' http://127.0.0.1:8014/covers/ curl -sS -m 5 -I http://127.0.0.1:8014/covers/ 2>&1 | head -15 # seaweed filer for p in 18888 8888 8333 8334; do curl -sS -m 3 -o /dev/null -w "port_${p}:%{http_code}\n" http://127.0.0.1:$p/ || echo port_${p}:FAIL done echo HOST_DONE """ for label, host, public in HOSTS: print(f"\n######## {label} {host} ########", flush=True) c = connect(host) _i, o, e = c.exec_command(SCRIPT, timeout=120) print((o.read() + e.read()).decode("utf-8", "replace"), flush=True) c.close() print(f"--- public probes {public} ---", flush=True) for path in ("/api/health", "/covers/", "/"): url = public + path t0 = time.time() try: req = urllib.request.Request(url, method="GET") with urllib.request.urlopen(req, timeout=15, context=CTX) as r: print(path, r.status, f"t={time.time()-t0:.2f}s", "ct=", r.headers.get("content-type"), flush=True) except Exception as ex: print(path, "ERR", ex, f"t={time.time()-t0:.2f}s", flush=True) print("ALL_DONE", flush=True)