62 lines
2.1 KiB
Python
62 lines
2.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Deploy per-group assign category (普通/时间段) to physical + VPS."""
|
|
import paramiko
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
LOCAL = Path(__file__).resolve().parents[1]
|
|
FILES = [
|
|
"backend/app/yt_assign_db.py",
|
|
"backend/app/models.py",
|
|
"backend/app/main.py",
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"frontend/src/components/YtAssignPanel.tsx",
|
|
]
|
|
|
|
|
|
def put(c, root, sudo=None):
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
tmp = f"/tmp/_cat_{Path(rel).name}"
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write((LOCAL / rel).read_bytes())
|
|
dst = f"{root}/{rel}"
|
|
cmd = (
|
|
f"echo '{sudo}' | sudo -S -p '' bash -lc \"install -m 644 {tmp} {dst}; sed -i 's/\\r$//' {dst}\""
|
|
if sudo
|
|
else f"install -m 644 {tmp} {dst}; sed -i 's/\\r$//' {dst}"
|
|
)
|
|
c.exec_command(cmd, timeout=30)[1].read()
|
|
print("ok", rel, flush=True)
|
|
sftp.close()
|
|
|
|
|
|
def build_restart(c, sudo=None):
|
|
inner = (
|
|
"cd /opt/douyinWEB/frontend && npm run build >/tmp/fe_cat.log 2>&1 && echo FE_OK || (tail -20 /tmp/fe_cat.log; echo FE_FAIL); "
|
|
"systemctl restart douyinweb-api douyinweb-web; "
|
|
"systemctl is-active douyinweb-api; systemctl is-active douyinweb-web"
|
|
)
|
|
cmd = f"echo '{sudo}' | sudo -S -p '' bash -lc '{inner}'" if sudo else inner
|
|
_i, o, e = c.exec_command(cmd, timeout=700)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
|
|
|
|
p = paramiko.SSHClient()
|
|
p.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
p.connect("107.173.30.245", 4014, "eric", "4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
print("PHYS", flush=True)
|
|
put(p, "/opt/douyinWEB", "4669805")
|
|
build_restart(p, "4669805")
|
|
p.close()
|
|
|
|
v = paramiko.SSHClient()
|
|
v.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
v.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=40, allow_agent=False, look_for_keys=False)
|
|
print("VPS", flush=True)
|
|
put(v, "/opt/douyinWEB")
|
|
build_restart(v)
|
|
v.close()
|
|
print("DONE", flush=True)
|