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>
47 lines
1.4 KiB
Python
47 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Finish clash S3 sync on server after deploy."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
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: str, timeout: int = 900) -> str:
|
|
_, out, err = c.exec_command(cmd, timeout=timeout)
|
|
return (out.read() + err.read()).decode("utf-8", "replace").strip()
|
|
|
|
|
|
for i in range(30):
|
|
st = run("systemctl is-active douyinweb-api", timeout=30)
|
|
print("api", i, st)
|
|
if st == "active":
|
|
break
|
|
if i in (2, 10):
|
|
run("systemctl restart douyinweb-api", timeout=30)
|
|
time.sleep(3)
|
|
|
|
# Load S3 env from systemd Environment= and run publish
|
|
cmd = r"""
|
|
set -e
|
|
cd /opt/douyinWEB
|
|
# extract DY_S3_* from unit Environment
|
|
eval $(systemctl show douyinweb-api -p Environment --value | tr ' ' '\n' | grep '^DY_S3_' | sed 's/^/export /')
|
|
export DY_S3_ENABLED="${DY_S3_ENABLED:-1}"
|
|
/opt/douyinWEB/backend/.venv/bin/python scripts/_publish_clash.py --force
|
|
"""
|
|
print("[sync clash]")
|
|
print(run(cmd, timeout=900))
|
|
|
|
print("[api clash]", run("curl -s http://127.0.0.1:8014/api/clash | head -c 1200", timeout=60))
|
|
print("[page]", run("curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:4015/clash", timeout=30))
|
|
c.close()
|
|
print("DONE")
|