douyinWEB/scripts/_deploy_tiktok.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

74 lines
2.1 KiB
Python

"""Deploy TikTok: stash server code conflicts, pull, restart. Never touch monitor.db."""
import paramiko
import time
HOST = "107.173.30.245"
USER = "root"
PASSWORD = "Xiao4669805"
REPO = "/opt/douyinWEB"
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd, timeout=300):
_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()
return o, e
print("[git status before]")
o, _ = run(f"cd {REPO} && git status --short | head -20")
print(o.encode("ascii", "replace").decode())
print("[stash tracked code changes only]")
o, e = run(
f"cd {REPO} && git stash push -m 'pre-tiktok-deploy' "
f"-- backend/app/db.py backend/app/main.py backend/app/models.py 2>&1",
timeout=30,
)
print(o or e)
print("[git pull]")
o, e = run(f"cd {REPO} && git pull origin dev 2>&1", timeout=60)
print(o or e)
print("[git log]")
o, _ = run(f"cd {REPO} && git log --oneline -2")
print(o)
print("[verify monitor.db untouched]")
o, _ = run(f"ls -lh {REPO}/backend/data/monitor.db")
print(o)
print("[restart api]")
c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1", timeout=5)
time.sleep(10)
o, _ = run("systemctl is-active douyinweb-api")
print("api:", o)
print("[npm build]")
o, _ = run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -8", timeout=360)
print(o.encode("ascii", "replace").decode())
print("[restart web]")
c.exec_command("systemctl restart douyinweb-web >/dev/null 2>&1", timeout=5)
time.sleep(6)
o, _ = run("systemctl is-active douyinweb-web")
print("web:", o)
print("[verify tiktok api]")
o, _ = run(
f"curl -s -o /dev/null -w '%{{http_code}}' http://127.0.0.1:8014/api/tiktok/setup 2>/dev/null || echo fail"
)
print("tiktok/setup HTTP:", o)
print("[verify shorts api]")
o, _ = run(
f"curl -s -o /dev/null -w '%{{http_code}}' http://127.0.0.1:8014/api/shorts/status 2>/dev/null || echo fail"
)
print("shorts/status HTTP:", o)
c.close()
print("DONE")