126 lines
3.9 KiB
Python
126 lines
3.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Finish dylive half only — chunked SFTP with progress (no silent hang)."""
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
ROOT = Path(r"c:\Users\admin\Desktop\douyinWEB")
|
|
PASS = "Xiao4669805"
|
|
HOST = "107.173.30.245"
|
|
LOCAL_HASH = {
|
|
"backend/app/douyin.py": hashlib.sha256(
|
|
(ROOT / "backend/app/douyin.py").read_bytes()
|
|
).hexdigest()[:12],
|
|
"frontend/src/components/YtRelayProStatusPanel.tsx": hashlib.sha256(
|
|
(ROOT / "frontend/src/components/YtRelayProStatusPanel.tsx").read_bytes()
|
|
).hexdigest()[:12],
|
|
}
|
|
|
|
|
|
def connect():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(8):
|
|
try:
|
|
print(f"ssh {HOST} try {i}...", flush=True)
|
|
c.connect(
|
|
HOST,
|
|
22,
|
|
"root",
|
|
PASS,
|
|
timeout=30,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
banner_timeout=90,
|
|
)
|
|
print("ssh ok", flush=True)
|
|
return c
|
|
except Exception as e:
|
|
print(f"ssh fail: {e}", flush=True)
|
|
time.sleep(1 + i)
|
|
raise SystemExit("ssh_fail")
|
|
|
|
|
|
def put_progress(sftp, local: Path, remote: str):
|
|
size = local.stat().st_size
|
|
print(f"upload {local.name} ({size/1e6:.1f}MB) -> {remote}", flush=True)
|
|
last = [0.0]
|
|
|
|
def cb(sent, total):
|
|
now = time.time()
|
|
if now - last[0] >= 2.0 or sent == total:
|
|
pct = 100.0 * sent / total if total else 0
|
|
print(f" {local.name}: {pct:.0f}% ({sent/1e6:.1f}/{total/1e6:.1f}MB)", flush=True)
|
|
last[0] = now
|
|
|
|
sftp.put(str(local), remote, callback=cb)
|
|
print(f" {local.name}: done", flush=True)
|
|
|
|
|
|
def run(c, cmd, timeout=180):
|
|
print(f"$ {cmd[:100]}...", flush=True)
|
|
_i, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
|
|
chan = o.channel
|
|
start = time.time()
|
|
while True:
|
|
if chan.recv_ready():
|
|
sys.stdout.write(chan.recv(4096).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
if chan.recv_stderr_ready():
|
|
sys.stdout.write(chan.recv_stderr(4096).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
if chan.exit_status_ready():
|
|
while chan.recv_ready():
|
|
sys.stdout.write(chan.recv(4096).decode("utf-8", "replace"))
|
|
sys.stdout.flush()
|
|
break
|
|
if time.time() - start > timeout:
|
|
print("TIMEOUT", flush=True)
|
|
break
|
|
time.sleep(0.15)
|
|
code = chan.recv_exit_status()
|
|
print(f"\n[exit {code}]", flush=True)
|
|
return code
|
|
|
|
|
|
print("local hashes:", LOCAL_HASH, flush=True)
|
|
c = connect()
|
|
sftp = c.open_sftp()
|
|
put_progress(sftp, ROOT / "scripts/_src-recv-fix.tgz", "/tmp/src-recv-fix.tgz")
|
|
put_progress(sftp, ROOT / "scripts/_next-recv-fix.tgz", "/tmp/next-recv-fix.tgz")
|
|
sftp.close()
|
|
|
|
code = run(
|
|
c,
|
|
r"""
|
|
set -e
|
|
tar -C /opt/douyinWEB -xzf /tmp/src-recv-fix.tgz
|
|
systemctl restart douyinweb-api
|
|
systemctl stop douyinweb-web || true
|
|
rm -rf /opt/douyinWEB/frontend/.next.bak_recv
|
|
mv /opt/douyinWEB/frontend/.next /opt/douyinWEB/frontend/.next.bak_recv 2>/dev/null || true
|
|
tar -C /opt/douyinWEB/frontend -xzf /tmp/next-recv-fix.tgz
|
|
systemctl start douyinweb-web
|
|
sleep 2
|
|
echo api=$(systemctl is-active douyinweb-api) web=$(systemctl is-active douyinweb-web)
|
|
python3 - <<'PY'
|
|
import hashlib, pathlib
|
|
for rel in ['backend/app/douyin.py','frontend/src/components/YtRelayProStatusPanel.tsx']:
|
|
p=pathlib.Path('/opt/douyinWEB')/rel
|
|
print('hash', hashlib.sha256(p.read_bytes()).hexdigest()[:12], rel)
|
|
PY
|
|
grep -n 'YouTube 接流中\|推流接流' /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx | head -5
|
|
""",
|
|
timeout=180,
|
|
)
|
|
c.close()
|
|
if code != 0:
|
|
raise SystemExit(f"dylive_fail {code}")
|
|
print("ALL_DONE", LOCAL_HASH, flush=True)
|