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

61 lines
1.8 KiB
Python

"""Deploy channel/account enable switches (direct SFTP when git push unavailable)."""
import paramiko
import time
HOST = "107.173.30.245"
USER = "root"
PASSWORD = "Xiao4669805"
REPO = "/opt/douyinWEB"
LOCAL = "C:/Users/admin/Desktop/douyinWEB"
FILES = [
"backend/app/db.py",
"backend/app/main.py",
"backend/app/tiktok_db.py",
"backend/app/x2_db.py",
"backend/app/x_clips_db.py",
"backend/app/x_clips_pipeline.py",
"backend/app/yt_long_db.py",
"frontend/src/app/shorts/page.tsx",
"frontend/src/app/tiktok/page.tsx",
"frontend/src/app/x/page.tsx",
"frontend/src/app/yt-long/page.tsx",
]
def main() -> None:
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)
sftp = c.open_sftp()
for rel in FILES:
remote = f"{REPO}/{rel}"
local = f"{LOCAL}/{rel}"
print(f"upload {rel}")
sftp.put(local, remote)
sftp.close()
print("[restart api]")
c.exec_command("systemctl restart douyinweb-api >/dev/null 2>&1", timeout=5)
time.sleep(8)
_, out, _ = c.exec_command("systemctl is-active douyinweb-api", timeout=15)
print("api:", out.read().decode().strip())
print("[npm build]")
_, out, _ = c.exec_command(f"cd {REPO}/frontend && npm run build 2>&1 | tail -8", timeout=360)
print(out.read().decode("utf-8", "replace").encode("ascii", "replace").decode())
print("[restart web]")
c.exec_command("systemctl restart douyinweb-web >/dev/null 2>&1", timeout=5)
time.sleep(5)
_, out, _ = c.exec_command("systemctl is-active douyinweb-web", timeout=15)
print("web:", out.read().decode().strip())
c.close()
print("DONE")
if __name__ == "__main__":
main()