69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
PASS = "Xiao4669805"
|
|
HOST = "108.174.50.68"
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(15):
|
|
try:
|
|
c.connect(
|
|
HOST,
|
|
22,
|
|
"root",
|
|
PASS,
|
|
timeout=50,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=120,
|
|
)
|
|
print("connected", i, flush=True)
|
|
break
|
|
except Exception as e:
|
|
print("retry", i, type(e).__name__, flush=True)
|
|
time.sleep(4 + i)
|
|
else:
|
|
print("ssh_fail")
|
|
return 1
|
|
|
|
sftp = c.open_sftp()
|
|
for rel, dst in [
|
|
("backend/app/youtube_relay_pipeline.py", "/opt/douyinWEB/backend/app/youtube_relay_pipeline.py"),
|
|
("backend/tests/test_relay_normal_auto.py", "/opt/douyinWEB/backend/tests/test_relay_normal_auto.py"),
|
|
]:
|
|
data = (ROOT / rel).read_bytes().replace(b"\r\n", b"\n")
|
|
tmp = f"/tmp/_excl_{Path(rel).name}"
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write(data)
|
|
_, o, e = c.exec_command(f"cat {tmp} > {dst} && echo OK {dst}", timeout=30)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
sftp.close()
|
|
|
|
remote = """
|
|
systemctl restart douyinweb-api
|
|
for i in $(seq 1 20); do
|
|
c=$(curl -sS -m 3 -o /dev/null -w '%{http_code}' http://127.0.0.1:8014/api/health || echo x)
|
|
echo health_$i=$c
|
|
[ "$c" = "200" ] && break
|
|
sleep 2
|
|
done
|
|
systemctl is-active douyinweb-api
|
|
"""
|
|
_, o, e = c.exec_command(remote, timeout=90)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"), flush=True)
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|