# -*- coding: utf-8 -*- """Finish dy.nomadro.live deploy: start services, nginx, certbot.""" import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace") HOST = "108.174.50.68" DOMAIN = "dy.nomadro.live" PUBLIC_BASE = f"https://{DOMAIN}" FINISH_SH = r"""#!/usr/bin/env bash set -euo pipefail source /etc/douyinweb.env APP_DIR=/opt/douyinWEB ADMIN_PASS='Xiao4669805@' API_PORT=${API_PORT:-8014} WEB_PORT=${WEB_PORT:-4015} PB_PORT=${PB_PORT:-8092} S3_PORT=${S3_PORT:-8333} S3_BUCKET=${S3_BUCKET:-douyin-covers} S3_ACCESS=${S3_ACCESS:-douyin} PB_ADMIN_EMAIL="${ADMIN_USER}@${DOMAIN}" log() { printf '\n[%s] %s\n' "$(date '+%F %T')" "$*"; } log "start all douyinweb units" systemctl daemon-reload systemctl enable --now \ douyinweb-sw-master douyinweb-sw-volume douyinweb-sw-filer douyinweb-s3 \ douyinweb-pb douyinweb-yt douyinweb-api douyinweb-web sleep 8 systemctl is-active douyinweb-sw-master douyinweb-sw-volume douyinweb-sw-filer douyinweb-s3 \ douyinweb-pb douyinweb-yt douyinweb-api douyinweb-web || true log "pb superuser + s3 bucket" "$APP_DIR/pb/pocketbase" superuser upsert "$PB_ADMIN_EMAIL" "$ADMIN_PASS" || true export S3_PORT S3_ACCESS S3_SECRET S3_BUCKET "$APP_DIR/backend/.venv/bin/python" - </etc/nginx/conf.d/dy-nomadro-live.conf < int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False) remote = "/tmp/finish_dy.sh" sftp = c.open_sftp() with sftp.file(remote, "w") as f: f.write(FINISH_SH) sftp.chmod(remote, 0o755) sftp.close() chan = c.get_transport().open_session() chan.settimeout(600) chan.get_pty(width=200, height=50) chan.exec_command(f"bash {remote}") while True: if chan.recv_ready(): print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True) if chan.recv_stderr_ready(): print(chan.recv_stderr(65535).decode("utf-8", "replace"), end="", flush=True) if chan.exit_status_ready() and not chan.recv_ready() and not chan.recv_stderr_ready(): break time.sleep(0.3) while chan.recv_ready(): print(chan.recv(65535).decode("utf-8", "replace"), end="", flush=True) code = chan.recv_exit_status() c.close() print(f"\nexit {code}") return code if __name__ == "__main__": raise SystemExit(main())