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>
45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
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, timeout=30):
|
|
print("$", cmd[:160])
|
|
_s, out, err = c.exec_command(cmd, timeout=timeout)
|
|
o = out.read().decode("utf-8", "replace").strip()
|
|
e = err.read().decode("utf-8", "replace").strip()
|
|
if o:
|
|
print(o)
|
|
if e and "warn" not in e.lower():
|
|
print("ERR:", e[:300])
|
|
return o
|
|
|
|
|
|
for name in ("douyinweb-api", "douyinweb-web"):
|
|
st = run(f"systemctl is-active {name}")
|
|
if st.strip() != "active":
|
|
run(f"systemctl start {name}")
|
|
|
|
for i in range(20):
|
|
time.sleep(5)
|
|
api = run("systemctl is-active douyinweb-api")
|
|
web = run("systemctl is-active douyinweb-web")
|
|
health = run("curl -sS -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health")
|
|
print(f"wait {i+1} api={api} web={web} health={health}")
|
|
if api.strip() == "active" and web.strip() == "active" and health.strip() == "200":
|
|
break
|
|
if api.strip() in {"failed", "inactive"}:
|
|
run("systemctl start douyinweb-api")
|
|
if web.strip() in {"failed", "inactive"}:
|
|
run("systemctl start douyinweb-web")
|
|
|
|
run("systemctl is-active douyinweb-api douyinweb-web")
|
|
c.close()
|
|
print("DONE")
|