98 lines
3.3 KiB
Python
98 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Finish deploy: wait VPS API + sudo tee on physical."""
|
|
from __future__ import annotations
|
|
|
|
import base64
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
FILES = [
|
|
"backend/app/youtube_neko.py",
|
|
"backend/app/youtube_relay_pipeline.py",
|
|
"backend/app/ops_neko.py",
|
|
"backend/neko/cdp_studio_scrape.py",
|
|
"backend/neko/live-ops-extension/content.js",
|
|
]
|
|
|
|
|
|
def run(c, cmd, t=90):
|
|
_, o, e = c.exec_command(cmd, timeout=t)
|
|
o.channel.settimeout(t)
|
|
try:
|
|
return (o.read() + e.read()).decode("utf-8", "replace")
|
|
except Exception as ex:
|
|
return f"ERR {type(ex).__name__}: {ex}"
|
|
|
|
|
|
def main():
|
|
# VPS
|
|
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)
|
|
print("VPS active:", run(c, "systemctl is-active douyinweb-api", 15).strip())
|
|
for i in range(12):
|
|
h = run(c, "curl -sS -m 3 -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || echo x", 10).strip()
|
|
print(f" health try{i}", h)
|
|
if h == "200":
|
|
break
|
|
if i == 0:
|
|
print(run(c, "systemctl restart douyinweb-api", 40).strip())
|
|
time.sleep(3)
|
|
# marker check
|
|
print(
|
|
"VPS marker",
|
|
run(
|
|
c,
|
|
"grep -c encoder_lost /opt/douyinWEB/backend/app/youtube_neko.py /opt/douyinWEB/backend/neko/cdp_studio_scrape.py /opt/douyinWEB/backend/neko/live-ops-extension/content.js",
|
|
15,
|
|
).strip(),
|
|
)
|
|
c.close()
|
|
|
|
# Physical via sudo tee
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 4014, "eric", "4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
for rel in FILES:
|
|
data = (ROOT / rel).read_bytes()
|
|
b64 = base64.b64encode(data).decode("ascii")
|
|
remote = f"/opt/douyinWEB/{rel.replace(chr(92), '/')}"
|
|
# write via sudo bash -c with base64
|
|
cmd = (
|
|
f"echo {b64} | base64 -d | sudo tee {remote} >/dev/null && "
|
|
f"sudo chmod 644 {remote} && echo OK {remote}"
|
|
)
|
|
print(run(c, cmd, 40).strip())
|
|
print(
|
|
run(
|
|
c,
|
|
r"""
|
|
sudo systemctl restart douyinweb-api 2>/dev/null || sudo systemctl restart douyinweb 2>/dev/null || true
|
|
sleep 3
|
|
systemctl is-active douyinweb-api 2>/dev/null; systemctl is-active douyinweb 2>/dev/null
|
|
curl -sS -m 5 -o /dev/null -w 'health=%{http_code}\n' http://127.0.0.1:8014/api/health || true
|
|
# sync scrape into ops-neko-1
|
|
for i in 1 2; do
|
|
n=douyinweb-ops-neko-$i
|
|
docker inspect $n >/dev/null 2>&1 || continue
|
|
sudo docker cp /opt/douyinWEB/backend/neko/cdp_studio_scrape.py $n:/etc/neko/cdp_studio_scrape.py 2>/dev/null || true
|
|
sudo docker cp /opt/douyinWEB/backend/neko/live-ops-extension/content.js $n:/etc/neko/live-ops-extension/content.js 2>/dev/null || true
|
|
done
|
|
# classify now
|
|
sudo docker exec douyinweb-ops-neko-1 python3 /etc/neko/cdp_studio_scrape.py 2>/dev/null | tail -1 | head -c 900
|
|
""",
|
|
70,
|
|
)
|
|
)
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|