douyinWEB/scripts/move_web_4015.py
eric a360eec2ba Document slots/covers/PB ops UX and sync feature pass to main.
Ship zombie reconcile, S3 covers, session end/drill-down, rooms ops, and refresh README for production.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 20:07:15 -05:00

83 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
import paramiko
HOST = "107.173.30.245"
APP = "/opt/douyinWEB"
WEB = 4015
API = 8014
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
cmd = f"""
set -e
systemctl stop douyinweb-web || true
cat >/etc/systemd/system/douyinweb-web.service <<EOF
[Unit]
Description=DouyinWEB Next.js
After=network.target douyinweb-api.service
[Service]
Type=simple
WorkingDirectory={APP}/frontend
ExecStart=/usr/bin/npm run start -- --hostname 0.0.0.0 --port {WEB}
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
EOF
# ensure rewrite points to API
cat > {APP}/frontend/next.config.mjs <<'EOF'
/** @type {{import('next').NextConfig}} */
const nextConfig = {{
reactStrictMode: true,
async rewrites() {{
return [
{{ source: "/api/:path*", destination: "http://127.0.0.1:{API}/api/:path*" }},
{{ source: "/covers/:path*", destination: "http://127.0.0.1:{API}/covers/:path*" }},
];
}},
}};
export default nextConfig;
EOF
cd {APP}
git fetch origin && git reset --hard origin/main
# restore rewrite after reset
cat > frontend/next.config.mjs <<'EOF'
/** @type {{import('next').NextConfig}} */
const nextConfig = {{
reactStrictMode: true,
async rewrites() {{
return [
{{ source: "/api/:path*", destination: "http://127.0.0.1:{API}/api/:path*" }},
{{ source: "/covers/:path*", destination: "http://127.0.0.1:{API}/covers/:path*" }},
];
}},
}};
export default nextConfig;
EOF
cd frontend && npm run build
systemctl daemon-reload
systemctl enable douyinweb-web
systemctl restart douyinweb-api douyinweb-web
sleep 7
ss -lntp | grep -E ':{WEB}|:{API}|:8333'
systemctl is-active douyinweb-web douyinweb-api
curl -s -o /dev/null -w 'web:%{{http_code}}\\n' --max-time 20 http://127.0.0.1:{WEB}/
curl -s http://127.0.0.1:{API}/api/sessions/active | python3 -c "import sys,json; d=json.load(sys.stdin); print('active',d.get('total'));
[print(s.get('anchor_name'), s.get('cover_url')) for s in (d.get('sessions') or [])[:5]]"
SID=$(curl -s http://127.0.0.1:{API}/api/sessions/active | python3 -c "import sys,json; d=json.load(sys.stdin); print((d.get('sessions') or [{{}}])[0].get('id',''))")
curl -s -o /dev/null -w 'cover:%{{http_code}} size:%{{size_download}}\\n' --max-time 20 http://127.0.0.1:{API}/api/sessions/$SID/cover
curl -s -o /dev/null -w 'cover_via_web:%{{http_code}}\\n' --max-time 20 http://127.0.0.1:{WEB}/api/sessions/$SID/cover
"""
_, o, _ = c.exec_command(cmd, timeout=600, get_pty=True)
print(o.read().decode("utf-8", errors="replace")[-5000:])
c.close()
print(f"\nOpen http://{HOST}:{WEB}/")