douyinWEB/scripts/_deploy_tiktok_uc_fix.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

59 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy TikTok cookie upload fix (lazy Browser import + pip deps). No DB writes."""
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PY = "/opt/douyinWEB/backend/.venv/bin/python"
PIP = "/opt/douyinWEB/backend/.venv/bin/pip"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd: str, timeout: int = 420) -> str:
print("$", cmd[:200])
_s, out, err = c.exec_command(cmd, timeout=timeout)
o = out.read().decode("utf-8", "replace").strip()
e = err.read().decode("utf-8", "replace").strip()
if o:
print(o)
if e and "warn" not in e.lower():
print("ERR:", e[:500])
return o
run("cd /opt/douyinWEB && git pull origin dev 2>&1", timeout=60)
run(f"{PIP} install -q python-dotenv fake-useragent requests-auth-aws-sigv4 2>&1", timeout=120)
run(f"cd /opt/douyinWEB && {PY} scripts/setup_tiktok_uploader.py 2>&1", timeout=300)
print("\n=== restart api ===")
c.exec_command("systemctl restart douyinweb-api", timeout=5)
for i in range(18):
time.sleep(5)
st = run("systemctl is-active douyinweb-api")
if st.strip() == "active":
health = run("curl -sS -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health")
if health.strip() == "200":
break
print(f"wait {i+1}")
run("cd /opt/douyinWEB/frontend && npm run build 2>&1 | tail -6", timeout=420)
c.exec_command("systemctl restart douyinweb-web", timeout=5)
time.sleep(8)
run("systemctl is-active douyinweb-api douyinweb-web")
# Smoke: import upload path without undetected_chromedriver
run(
f"cd /opt/douyinWEB/backend && {PY} -c \""
"import sys; sys.path.insert(0,'third_party/TiktokAutoUploader'); "
"from tiktok_uploader.tiktok import upload_video; print('import_ok')\" 2>&1",
timeout=30,
)
c.close()
print("DONE")