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

79 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy disk/perf hardening for clip pipelines."""
import base64
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REPO = "/opt/douyinWEB"
BRANCH = "test1"
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, timeout=600):
_, o, e = c.exec_command(cmd, timeout=timeout)
out = (o.read() + e.read()).decode("utf-8", "replace").strip()
print(out[-7000:] if len(out) > 7000 else out, flush=True)
return out
def run_py(code: str, label: str):
b64 = base64.b64encode(code.encode("utf-8")).decode("ascii")
print(f"[{label}]")
return run(
f"cd {REPO}/backend && echo {b64} | base64 -d > /tmp/_disk_harden.py "
f"&& PYTHONPATH=. .venv/bin/python /tmp/_disk_harden.py"
)
print(
"[pull]",
run(
f"cd {REPO} && git stash push -u -m auto-disk || true; "
f"git fetch origin {BRANCH} && git pull --ff-only origin {BRANCH} && git log --oneline -1"
),
)
run_py(
r"""
from app import db
from app.clip_retention import purge_stale_clips, disk_free_gb, disk_ok_for_record
from app.clip_cascade import ensure_source_covers_platforms
db.init_db()
db.update_settings_map({
'yt_long_max_concurrent': 1,
'yt_long_live_sample_batch': 1,
'yt_long_delete_clip_after_upload': True,
'shorts_delete_clip_after_upload': True,
'tiktok_delete_clip_after_upload': True,
'x_clips_delete_clip_after_post': True,
'clips_max_age_hours': 24,
'clips_min_free_gb': 12,
})
ensure_source_covers_platforms()
print('free_before', round(disk_free_gb(),2), 'ok', disk_ok_for_record())
print('purge', purge_stale_clips())
print('free_after', round(disk_free_gb(),2))
m=db.get_settings_map()
print({k:m.get(k) for k in ['yt_long_max_concurrent','yt_long_live_sample_batch','yt_long_source_daily_max','yt_long_daily_max','clips_max_age_hours','clips_min_free_gb','yt_long_delete_clip_after_upload']})
""",
"patch",
)
run("systemctl restart douyinweb-api")
for _ in range(40):
if run("systemctl is-active douyinweb-api", timeout=15) == "active":
print("[api] active")
break
time.sleep(2)
time.sleep(3)
print("[df]", run("df -h / | tail -1; free -h | head -2; uptime"))
print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web"))
# frontend only small text change none this round - skip full build if only backend
# still restart not needed for web if no frontend change - we have no frontend in this commit? check
c.close()
print("DONE")