douyinWEB/scripts/_deploy_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

68 lines
3.3 KiB
Python

# -*- coding: utf-8 -*-
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REPO = "/opt/douyinWEB"
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[-5000:] if len(out) > 5000 else out, flush=True)
return out
print("[pull]", run(f"cd {REPO} && git stash push -u -m auto-harden || true; git pull --ff-only origin test1 && git log --oneline -1"))
print("[clear yt_long legacy templates]")
run(r"""cd /opt/douyinWEB/backend && PYTHONPATH=. .venv/bin/python - <<'PY'
from app import db
db.init_db()
m = db.get_settings_map()
patch = {}
if str(m.get('yt_long_title_template') or '').strip() in ('{anchor} street food live', '{anchor}'):
patch['yt_long_title_template'] = ''
if str(m.get('yt_long_description_template') or '').strip() in ('{anchor}\n{url}', '{anchor}\n{url}\n#StreetFood #Live'):
patch['yt_long_description_template'] = ''
if 'x_clips_auto_post_paused_date' not in m:
patch['x_clips_auto_post_paused_date'] = ''
if patch:
db.update_settings_map(patch)
print('patched', patch)
else:
print('no template patch needed')
PY""")
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(4)
print("[verify]")
print(run(r"""cd /opt/douyinWEB/backend && PYTHONPATH=. .venv/bin/python - <<'PY'
from app import db, yt_long_db
from app.yt_long_pipeline import yt_long_pipeline, build_yt_long_copy
from collections import Counter
db.init_db()
st = yt_long_pipeline.status()
print('yt_long', {k: st.get(k) for k in ['enabled','running','quota_used','quota_gap','daily_max','last_error']})
jobs = yt_long_db.list_yt_long_jobs(limit=30)
print('jobs', dict(Counter(j.get('status') for j in jobs)))
chs = yt_long_db.list_yt_long_channels(enabled=True)
if chs:
cpy = build_yt_long_copy({'anchor_name':'test','room_id':'1','source_url':''}, chs[0], db.get_settings_map())
print('seo_title', cpy['title'][:70], 'src', cpy['title_source'])
mon = db.get_settings_map()
print('x_auto_post', mon.get('x_clips_auto_post'), 'paused_date', mon.get('x_clips_auto_post_paused_date'))
print('yt_title_tpl', repr(mon.get('yt_long_title_template')))
PY"""))
print("[build]", run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -n 12", timeout=600))
run("systemctl restart douyinweb-web")
print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web"))
print("[health]", run("curl -sS -m 15 http://127.0.0.1:8014/api/health | python3 -c \"import sys,json;h=json.load(sys.stdin);print('ok',h.get('ok'));print('shorts', (h.get('shorts') or {}).get('running'), (h.get('shorts') or {}).get('quota_gap'));print('yt_long', (h.get('yt_long') or {}).get('running'), (h.get('yt_long') or {}).get('quota_used'), (h.get('yt_long') or {}).get('quota_gap'));print('monitor', (h.get('monitor') or {}).get('running'), (h.get('monitor') or {}).get('live_count'), (h.get('monitor') or {}).get('overdue',{}).get('count'))\""))
c.close()
print("DONE")