# -*- coding: utf-8 -*- """Deploy nomadro.com + api + admin to US VPS 108.174.50.68 from CN 82 mirror.""" from __future__ import annotations import io import sys import time import paramiko sys.stdout.reconfigure(encoding="utf-8", errors="replace", line_buffering=True) sys.stderr.reconfigure(encoding="utf-8", errors="replace", line_buffering=True) CN = ("82.157.112.245", "ubuntu", "Xiao4669805") US = ("108.174.50.68", "root", "Xiao4669805") def connect(host: str, user: str, password: str) -> paramiko.SSHClient: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( host, 22, user, password, timeout=60, allow_agent=False, look_for_keys=False, banner_timeout=120, ) return c def run(c: paramiko.SSHClient, cmd: str, timeout: int = 600, check: bool = True) -> tuple[int, str, str]: print(f"\n$ {cmd[:200]}", flush=True) chan = c.get_transport().open_session() chan.get_pty() chan.settimeout(timeout) chan.exec_command(cmd) buf = io.BytesIO() deadline = time.time() + timeout while True: if chan.recv_ready(): chunk = chan.recv(4096) if not chunk: break buf.write(chunk) sys.stdout.write(chunk.decode("utf-8", "replace")) sys.stdout.flush() if chan.recv_stderr_ready(): chunk = chan.recv_stderr(4096) buf.write(chunk) sys.stderr.write(chunk.decode("utf-8", "replace")) sys.stderr.flush() if chan.exit_status_ready(): # drain while chan.recv_ready(): chunk = chan.recv(4096) buf.write(chunk) sys.stdout.write(chunk.decode("utf-8", "replace")) sys.stdout.flush() while chan.recv_stderr_ready(): chunk = chan.recv_stderr(4096) buf.write(chunk) sys.stderr.write(chunk.decode("utf-8", "replace")) sys.stderr.flush() break if time.time() > deadline: chan.close() raise TimeoutError(f"cmd timed out: {cmd[:160]}") time.sleep(0.2) code = chan.recv_exit_status() text = buf.getvalue().decode("utf-8", "replace") if check and code != 0: raise RuntimeError(f"cmd failed ({code}): {cmd[:160]}\n{text[-2000:]}") return code, text, "" def put_text(c: paramiko.SSHClient, remote: str, content: str, mode: int = 0o644) -> None: sftp = c.open_sftp() try: with sftp.file(remote, "w") as f: f.write(content) sftp.chmod(remote, mode) finally: sftp.close() def ensure_sshpass_and_key(cn: paramiko.SSHClient, us: paramiko.SSHClient) -> None: """Install sshpass on CN; put CN pubkey into US authorized_keys for rsync.""" run( cn, "command -v sshpass >/dev/null || (sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq sshpass)", timeout=180, ) run(cn, "test -f ~/.ssh/id_ed25519 || ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519") _c, pubkey, _e = run(cn, "cat ~/.ssh/id_ed25519.pub", check=True) pubkey = pubkey.strip().splitlines()[-1].strip() run( us, "mkdir -p /root/.ssh && chmod 700 /root/.ssh && " f"grep -qxF '{pubkey}' /root/.ssh/authorized_keys 2>/dev/null || echo '{pubkey}' >> /root/.ssh/authorized_keys && " "chmod 600 /root/.ssh/authorized_keys", ) # trust US host key on CN run( cn, "mkdir -p ~/.ssh && chmod 700 ~/.ssh && " "ssh-keyscan -H 108.174.50.68 >> ~/.ssh/known_hosts 2>/dev/null; " "ssh -o StrictHostKeyChecking=accept-new -o BatchMode=yes root@108.174.50.68 'echo cn-to-us-ok'", timeout=60, ) BOOTSTRAP_US = r""" set -euo pipefail export DEBIAN_FRONTEND=noninteractive # Node 22 via NodeSource if needed NODE_MAJOR=$(node -v 2>/dev/null | sed 's/v//' | cut -d. -f1 || echo 0) if [ "${NODE_MAJOR:-0}" -lt 22 ]; then curl -fsSL https://deb.nodesource.com/setup_22.x | bash - apt-get install -y -qq nodejs fi node -v npm -v # pnpm if ! command -v pnpm >/dev/null 2>&1; then npm install -g pnpm@9 fi # also ensure /usr/local/bin/pnpm (systemd expects it) if [ ! -x /usr/local/bin/pnpm ]; then ln -sf "$(command -v pnpm)" /usr/local/bin/pnpm fi pnpm -v apt-get install -y -qq python3-venv python3-pip rsync curl ca-certificates mkdir -p /var/www/nomadro.cn /opt/nomadmini/backend /opt/nomadmini/data \ /www/wwwroot/admin.nomadro.com /var/www/nomadro-data/social /var/www/nomadro-data/community \ /var/www/acme /etc/nomadro /var/log/nomadro /etc/nginx/sites-available /etc/nginx/sites-enabled # enable sites-enabled include if missing if ! grep -q 'sites-enabled' /etc/nginx/nginx.conf; then sed -i '/include \/etc\/nginx\/conf.d\/\*\.conf;/a\ include /etc/nginx/sites-enabled/*;' /etc/nginx/nginx.conf fi echo BOOTSTRAP_OK """ PORTAL_ENV = """NOMADRO_PUBLIC_ORIGIN=https://nomadro.com # NTFY optional on US # NTFY_BASE_URL= # NTFY_TOPIC=nomadro CENTRIFUGO_ENABLED=false API_URL=http://127.0.0.1:8020 """ API_ENV = """DEBUG=false WX_ALLOW_DEVTOOLS_LOGIN=true JWT_SECRET=nomadro-jwt-prod-us-2026 ADMIN_USERNAME=hackrobot ADMIN_PASSWORD=Xiao4669805@ USE_POCKETBASE=false PUBLIC_API_BASE=https://api.nomadro.com ADMIN_ORIGIN=https://admin.nomadro.com CORS_ORIGINS=https://admin.nomadro.com,https://api.nomadro.com,https://nomadro.com,https://www.nomadro.com DEFAULT_PRODUCT_ID=ebook_unlock_default DEFAULT_PRICE_FEN=100 DEFAULT_UNLOCK_PERCENT=30 SQLITE_PATH=/opt/nomadmini/data/nomadmini.db NTFY_ENABLED=false WX_PAY_ENV=1 """ NOMADRO_SERVICE = """[Unit] Description=Nomadro Next.js App (nomadro.com) After=network.target [Service] EnvironmentFile=-/etc/nomadro/portal.env Type=simple WorkingDirectory=/var/www/nomadro.cn Environment=PORT=4003 Environment=NODE_ENV=production Environment=HOSTNAME=127.0.0.1 ExecStart=/usr/local/bin/pnpm start Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target """ API_SERVICE = """[Unit] Description=Nomadmini FastAPI (api.nomadro.com) After=network.target [Service] Type=simple WorkingDirectory=/opt/nomadmini/backend EnvironmentFile=/opt/nomadmini/backend/.env Environment=SOCIAL_DB_PATH=/var/www/nomadro-data/social/social.db Environment=COMMUNITY_STORE_PATH=/var/www/nomadro-data/community/community_store.json ExecStart=/opt/nomadmini/backend/.venv/bin/uvicorn app.main:app --host 127.0.0.1 --port 8010 Restart=always RestartSec=3 [Install] WantedBy=multi-user.target """ SOCIAL_SERVICE = """[Unit] Description=Nomadro social API (isolated) After=network.target [Service] Type=simple WorkingDirectory=/var/www/nomadro.cn/apps/api Environment=HOST=127.0.0.1 Environment=PORT=8020 Environment=SOCIAL_ENABLED=true Environment=SOCIAL_DB_PATH=/var/www/nomadro-data/social/social.db Environment=PYTHONPATH=/var/www/nomadro.cn/apps/api:/var/www/nomadro.cn/apps/api/services ExecStart=/var/www/nomadro.cn/apps/api/.venv-social/bin/python -m uvicorn social_main:app --host 127.0.0.1 --port 8020 Restart=on-failure RestartSec=5 [Install] WantedBy=multi-user.target """ NGINX_PORTAL = r""" # HTTP — ACME + redirect server { listen 80; listen [::]:80; server_name nomadro.com www.nomadro.com; location ^~ /.well-known/acme-challenge/ { root /var/www/acme; default_type text/plain; allow all; } location = /api/config { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Host api.nomadro.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; add_header Cache-Control "no-store"; } location = /api/config/meta { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Host api.nomadro.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; add_header Cache-Control "no-store"; } location ^~ /api/social/ { proxy_pass http://127.0.0.1:8020; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Social-Guest-Id $http_x_social_guest_id; } location / { return 301 https://$host$request_uri; } } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name nomadro.com www.nomadro.com; ssl_certificate /etc/letsencrypt/live/nomadro.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/nomadro.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; client_max_body_size 32m; location = /api/config { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Host api.nomadro.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; add_header Cache-Control "no-store"; } location = /api/config/meta { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Host api.nomadro.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; add_header Cache-Control "no-store"; } location ^~ /api/social/ { proxy_pass http://127.0.0.1:8020; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Social-Guest-Id $http_x_social_guest_id; } location = /favicon.ico { alias /var/www/nomadro.cn/public/favicon.ico; access_log off; } location = /favicon.svg { alias /var/www/nomadro.cn/public/favicon.svg; access_log off; } location = /manifest.webmanifest { alias /var/www/nomadro.cn/public/manifest.webmanifest; default_type application/manifest+json; access_log off; } location / { proxy_pass http://127.0.0.1:4003; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 300s; proxy_send_timeout 300s; } } """ NGINX_API = r""" server { listen 80; listen [::]:80; server_name api.nomadro.com; location ^~ /.well-known/acme-challenge/ { root /var/www/acme; default_type text/plain; allow all; } location / { return 301 https://$host$request_uri; } } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name api.nomadro.com; client_max_body_size 32m; ssl_certificate /etc/letsencrypt/live/api.nomadro.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/api.nomadro.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; location ^~ /.well-known/acme-challenge/ { root /var/www/acme; allow all; } location /api/config/ws { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 3600s; proxy_buffering off; } location /api/ebook/config/ws { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 3600s; proxy_buffering off; } location / { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 300s; } } """ NGINX_ADMIN = r""" server { listen 80; listen [::]:80; server_name admin.nomadro.com; root /www/wwwroot/admin.nomadro.com; location ^~ /.well-known/acme-challenge/ { root /var/www/acme; default_type text/plain; allow all; } location / { return 301 https://$host$request_uri; } } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name admin.nomadro.com; root /www/wwwroot/admin.nomadro.com; index index.html; client_max_body_size 20m; ssl_certificate /etc/letsencrypt/live/admin.nomadro.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/admin.nomadro.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; location /api/ { proxy_pass http://127.0.0.1:8010/api/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /health { proxy_pass http://127.0.0.1:8010/health; proxy_set_header Host $host; } location /assets/ { try_files $uri =404; expires 30d; add_header Cache-Control "public, immutable"; } location / { try_files $uri $uri/ /index.html; } } """ # HTTP-only stubs used BEFORE certbot NGINX_HTTP_ONLY = r""" server { listen 80; listen [::]:80; server_name nomadro.com www.nomadro.com; location ^~ /.well-known/acme-challenge/ { root /var/www/acme; default_type text/plain; allow all; } location = /api/config { proxy_pass http://127.0.0.1:8010; proxy_set_header Host api.nomadro.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location = /api/config/meta { proxy_pass http://127.0.0.1:8010; proxy_set_header Host api.nomadro.com; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location ^~ /api/social/ { proxy_pass http://127.0.0.1:8020; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Social-Guest-Id $http_x_social_guest_id; } location / { proxy_pass http://127.0.0.1:4003; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } server { listen 80; listen [::]:80; server_name api.nomadro.com; location ^~ /.well-known/acme-challenge/ { root /var/www/acme; default_type text/plain; allow all; } location / { proxy_pass http://127.0.0.1:8010; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } server { listen 80; listen [::]:80; server_name admin.nomadro.com; root /www/wwwroot/admin.nomadro.com; index index.html; location ^~ /.well-known/acme-challenge/ { root /var/www/acme; default_type text/plain; allow all; } location /api/ { proxy_pass http://127.0.0.1:8010/api/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } location /health { proxy_pass http://127.0.0.1:8010/health; } location / { try_files $uri $uri/ /index.html; } } """ def main() -> int: print("=== connect CN ===", flush=True) cn = connect(*CN) print("=== connect US ===", flush=True) us = connect(*US) print("=== connected ===", flush=True) print("=== bootstrap US runtime ===") put_text(us, "/tmp/bootstrap_nomadro_us.sh", BOOTSTRAP_US, 0o755) run(us, "bash /tmp/bootstrap_nomadro_us.sh", timeout=600) print("=== ssh key CN -> US ===") ensure_sshpass_and_key(cn, us) print("=== rsync portal from CN (exclude huge unused) ===") # Keep path /var/www/nomadro.cn for Next compatibility rsync_portal = r""" set -euo pipefail RSYNC='rsync -aH --info=progress2 --delete' EXCLUDES=( --exclude node_modules/.cache --exclude .git --exclude apps/miniprogram --exclude apps/admin/node_modules --exclude '**/.tmp*' --exclude '*.log' --exclude apps/api/.venv --exclude apps/api/.venv-social ) # first sync code+build without node_modules to start services sooner? need node_modules for next start $RSYNC "${EXCLUDES[@]}" \ /var/www/nomadro.cn/ root@108.174.50.68:/var/www/nomadro.cn/ echo PORTAL_RSYNC_OK """ put_text(cn, "/tmp/rsync_portal_us.sh", rsync_portal, 0o755) run(cn, "bash /tmp/rsync_portal_us.sh", timeout=3600) print("=== rsync API backend ===") rsync_api = r""" set -euo pipefail rsync -aH --info=progress2 --delete \ --exclude .venv \ --exclude '__pycache__' \ --exclude '*.pyc' \ --exclude data \ /opt/nomadmini/backend/ root@108.174.50.68:/opt/nomadmini/backend/ # optional sqlite seed (empty ok) ssh root@108.174.50.68 'mkdir -p /opt/nomadmini/data' if [ -f /opt/nomadmini/data/nomadmini.db ]; then rsync -aH /opt/nomadmini/data/nomadmini.db root@108.174.50.68:/opt/nomadmini/data/nomadmini.db fi # social db if [ -f /var/www/nomadro-data/social/social.db ]; then rsync -aH /var/www/nomadro-data/social/social.db root@108.174.50.68:/var/www/nomadro-data/social/social.db fi if [ -f /var/www/nomadro-data/community/community_store.json ]; then rsync -aH /var/www/nomadro-data/community/community_store.json root@108.174.50.68:/var/www/nomadro-data/community/community_store.json fi echo API_RSYNC_OK """ put_text(cn, "/tmp/rsync_api_us.sh", rsync_api, 0o755) run(cn, "bash /tmp/rsync_api_us.sh", timeout=900) print("=== rsync admin SPA ===") rsync_admin = r""" set -euo pipefail rsync -aH --info=progress2 --delete \ /www/wwwroot/admin.nomadro.cn/ root@108.174.50.68:/www/wwwroot/admin.nomadro.com/ echo ADMIN_RSYNC_OK """ put_text(cn, "/tmp/rsync_admin_us.sh", rsync_admin, 0o755) run(cn, "bash /tmp/rsync_admin_us.sh", timeout=300) print("=== write envs + systemd on US ===") put_text(us, "/etc/nomadro/portal.env", PORTAL_ENV, 0o644) put_text(us, "/opt/nomadmini/backend/.env", API_ENV, 0o600) put_text(us, "/etc/systemd/system/nomadro.service", NOMADRO_SERVICE) put_text(us, "/etc/systemd/system/nomadmini-api.service", API_SERVICE) put_text(us, "/etc/systemd/system/nomadro-social.service", SOCIAL_SERVICE) print("=== recreate Python venvs on US ===") venv_cmd = r""" set -euo pipefail cd /opt/nomadmini/backend python3 -m venv .venv .venv/bin/pip install -U pip wheel .venv/bin/pip install -r requirements.txt # uvicorn often listed .venv/bin/pip install uvicorn fastapi 2>/dev/null || true cd /var/www/nomadro.cn/apps/api python3 -m venv .venv-social .venv-social/bin/pip install -U pip wheel if [ -f requirements.txt ]; then .venv-social/bin/pip install -r requirements.txt fi .venv-social/bin/pip install uvicorn fastapi 2>/dev/null || true # common social deps .venv-social/bin/pip install pydantic pydantic-settings httpx aiosqlite python-multipart 2>/dev/null || true echo VENV_OK """ put_text(us, "/tmp/venv_nomadro_us.sh", venv_cmd, 0o755) run(us, "bash /tmp/venv_nomadro_us.sh", timeout=900) print("=== enable + start services ===") run(us, "systemctl daemon-reload && systemctl enable nomadro.service nomadmini-api.service nomadro-social.service && systemctl restart nomadmini-api.service nomadro-social.service nomadro.service", timeout=120) time.sleep(4) run(us, "systemctl --no-pager --full status nomadmini-api.service nomadro-social.service nomadro.service | sed -n '1,80p'", check=False) run(us, "ss -lntp | grep -E '4003|8010|8020' || true", check=False) print("=== nginx HTTP stubs ===") put_text(us, "/etc/nginx/sites-available/nomadro-http.conf", NGINX_HTTP_ONLY) run( us, "ln -sfn /etc/nginx/sites-available/nomadro-http.conf /etc/nginx/sites-enabled/nomadro-http.conf && " "rm -f /etc/nginx/sites-enabled/nomadro.com.conf /etc/nginx/sites-enabled/api.nomadro.com.conf /etc/nginx/sites-enabled/admin.nomadro.com.conf && " "nginx -t && systemctl reload nginx", ) print("=== certbot ===") cert_cmd = r""" set -euo pipefail mkdir -p /var/www/acme certbot certonly --webroot -w /var/www/acme \ -d nomadro.com -d www.nomadro.com \ --non-interactive --agree-tos --email admin@nomadro.com --keep-until-expiring || true certbot certonly --webroot -w /var/www/acme \ -d api.nomadro.com \ --non-interactive --agree-tos --email admin@nomadro.com --keep-until-expiring || true certbot certonly --webroot -w /var/www/acme \ -d admin.nomadro.com \ --non-interactive --agree-tos --email admin@nomadro.com --keep-until-expiring || true ls -la /etc/letsencrypt/live/ || true """ put_text(us, "/tmp/certbot_nomadro.sh", cert_cmd, 0o755) run(us, "bash /tmp/certbot_nomadro.sh", timeout=300, check=False) # check certs _c, out, _e = run(us, "ls /etc/letsencrypt/live/nomadro.com/fullchain.pem /etc/letsencrypt/live/api.nomadro.com/fullchain.pem /etc/letsencrypt/live/admin.nomadro.com/fullchain.pem 2>&1", check=False) have_certs = "No such file" not in out and out.count("fullchain.pem") >= 3 if have_certs: print("=== install TLS nginx configs ===") put_text(us, "/etc/nginx/sites-available/nomadro.com.conf", NGINX_PORTAL) put_text(us, "/etc/nginx/sites-available/api.nomadro.com.conf", NGINX_API) put_text(us, "/etc/nginx/sites-available/admin.nomadro.com.conf", NGINX_ADMIN) run( us, "rm -f /etc/nginx/sites-enabled/nomadro-http.conf && " "ln -sfn /etc/nginx/sites-available/nomadro.com.conf /etc/nginx/sites-enabled/nomadro.com.conf && " "ln -sfn /etc/nginx/sites-available/api.nomadro.com.conf /etc/nginx/sites-enabled/api.nomadro.com.conf && " "ln -sfn /etc/nginx/sites-available/admin.nomadro.com.conf /etc/nginx/sites-enabled/admin.nomadro.com.conf && " "nginx -t && systemctl reload nginx", ) else: print("WARN: certs incomplete — leaving HTTP stubs active") print(out) print("=== smoke ===") smoke = r""" set +e echo '--- local ports ---' ss -lntp | grep -E ':80|:443|:4003|:8010|:8020' echo '--- curl local ---' curl -sS -o /dev/null -w 'portal4003:%{http_code}\n' http://127.0.0.1:4003/ || true curl -sS -o /dev/null -w 'api8010:%{http_code}\n' http://127.0.0.1:8010/health || true curl -sS -o /dev/null -w 'social8020:%{http_code}\n' http://127.0.0.1:8020/docs || true echo '--- curl domains ---' curl -sS -o /dev/null -w 'http_nomadro:%{http_code}\n' -H 'Host: nomadro.com' http://127.0.0.1/ || true curl -sS -o /dev/null -w 'https_nomadro:%{http_code}\n' --resolve nomadro.com:443:127.0.0.1 https://nomadro.com/ -k || true curl -sS -o /dev/null -w 'https_api:%{http_code}\n' --resolve api.nomadro.com:443:127.0.0.1 https://api.nomadro.com/health -k || true curl -sS -o /dev/null -w 'https_admin:%{http_code}\n' --resolve admin.nomadro.com:443:127.0.0.1 https://admin.nomadro.com/ -k || true curl -sS -o /dev/null -w 'public_nomadro:%{http_code}\n' https://nomadro.com/ || true curl -sS -o /dev/null -w 'public_api:%{http_code}\n' https://api.nomadro.com/health || true curl -sS -o /dev/null -w 'public_admin:%{http_code}\n' https://admin.nomadro.com/ || true systemctl is-active nomadro nomadmini-api nomadro-social nginx """ run(us, smoke, timeout=120, check=False) cn.close() us.close() print("\n=== DONE ===") return 0 if __name__ == "__main__": raise SystemExit(main())