douyinWEB/scripts/_run_new_vps_bootstrap.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
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>
2026-09-04 22:42:40 -05:00

67 lines
2.2 KiB
Python

# -*- coding: utf-8 -*-
"""Upload bootstrap_vps.sh and run it on a shared VPS. Does not touch existing services."""
import posixpath
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOST = "192.227.152.110"
USER = "root"
PASSWORD = "Leaf448772566"
LOCAL_SH = Path(__file__).resolve().parents[1] / "scripts" / "bootstrap_vps.sh"
REMOTE_SH = "/tmp/bootstrap_vps.sh"
ENV = {
"DOMAIN": "ypp.smallzhiyuns.com",
"ADMIN_USER": "dsx2016",
"ADMIN_PASS": "Leaf448772566",
"GIT_URL": "https://eric:Xiao4669805@gitea.dsx2020.com/eric/douyinWEB.git",
"GIT_BRANCH": "test1",
"FRESH": "1",
}
def main() -> None:
text = LOCAL_SH.read_bytes().replace(b"\r\n", b"\n").replace(b"\r", b"\n")
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
with sftp.file(REMOTE_SH, "wb") as f:
f.write(text)
sftp.chmod(REMOTE_SH, 0o755)
sftp.close()
print("uploaded", REMOTE_SH, "bytes", len(text), flush=True)
export = " ".join(f"{k}={paramiko.py3compat.u(v)!r}" if False else f"{k}='{v}'" for k, v in ENV.items())
cmd = f"{export} bash {REMOTE_SH}"
print("running bootstrap...", flush=True)
chan = c.get_transport().open_session()
chan.settimeout(1800)
chan.get_pty(width=160, height=40)
chan.exec_command(cmd)
while True:
if chan.recv_ready():
chunk = chan.recv(65535).decode("utf-8", "replace")
print(chunk, end="", flush=True)
if chan.recv_stderr_ready():
chunk = chan.recv_stderr(65535).decode("utf-8", "replace")
print(chunk, end="", flush=True)
if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready():
break
time.sleep(0.2)
while chan.recv_ready():
print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True)
code = chan.recv_exit_status()
c.close()
print("\nexit", code, flush=True)
raise SystemExit(code)
if __name__ == "__main__":
main()