douyinWEB/scripts/_stop_other_projects_confirm.py
2026-09-13 22:10:49 -05:00

88 lines
2.3 KiB
Python

#!/usr/bin/env python3
"""Confirm other-project stacks are stopped; stop again if any revived."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
UNITS = [
"nomadro.service",
"nomadro-api.service",
"nomadro-web.service",
"nomadro-router.service",
"nomadro-live-router.service",
"robook-api.service",
"robook-web.service",
"robook-pb.service",
"tiktok-promo-backend.service",
"tiktok-promo-frontend.service",
"tiktok-promo-pocketbase.service",
"xauto-web.service",
"xauto-pocketbase.service",
"ebook-api.service",
"hackrobot-web.service",
]
def connect():
last = None
for i in range(12):
try:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
22,
"root",
"Xiao4669805",
timeout=60,
banner_timeout=180,
allow_agent=False,
look_for_keys=False,
)
print("connected", i, flush=True)
return c
except Exception as ex:
last = ex
print("retry", i, type(ex).__name__, ex, flush=True)
time.sleep(6)
raise SystemExit(f"ssh failed: {last}")
def run(c, cmd, t=180):
print(f"\n$ {cmd[:220]}", flush=True)
_i, o, e = c.exec_command(cmd, timeout=t)
code = o.channel.recv_exit_status()
out = (o.read() + e.read()).decode("utf-8", "replace")
print(out[-7000:] if len(out) > 7000 else out, flush=True)
return code, out
def main() -> int:
c = connect()
try:
units = " ".join(UNITS)
run(c, f"systemctl stop {units}; systemctl disable {units}; echo OK", 240)
run(
c,
"echo '=== status ==='; "
+ "".join(
f'printf "%-42s active=%-12s enabled=%s\\n" "{u}" "$(systemctl is-active {u} 2>/dev/null)" "$(systemctl is-enabled {u} 2>/dev/null)"; '
for u in UNITS
),
120,
)
run(c, "uptime; free -h | head -2")
print("DONE", flush=True)
return 0
finally:
c.close()
if __name__ == "__main__":
raise SystemExit(main())