nomadro/deploy/social/mirotalk/pin_82_only.py
Eric 4789785f11 Ship remaining business changes across social API, miniprogram audit/book, VIP track, and deploy.
Includes social realtime entrypoints, weapp audit book surfaces, VIP analytics track routes, MiroTalk/Centrifugo deploy helpers, and related admin/config wiring. Excludes local DB dumps and .tmp probe scripts.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-01 17:10:10 +08:00

100 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Ensure MiroTalk for nomadro.cn is 82-only (mirotalk.nomadro.cn), not .com/107."""
from __future__ import annotations
import paramiko
HOST = "82.157.112.245"
USER = "ubuntu"
PASS = "Xiao4669805"
BASE = "/opt/nomadro-services/mirotalk"
def main() -> int:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=30, allow_agent=False, look_for_keys=False)
def run(cmd: str, t: int = 90) -> tuple[str, int]:
_i, o, e = c.exec_command(cmd, timeout=t)
out = o.read().decode("utf-8", "ignore")
err = e.read().decode("utf-8", "ignore")
return out + (("\n" + err) if err.strip() else ""), o.channel.recv_exit_status()
print("==== services")
out, _ = run(
"systemctl is-active mirotalk-p2p nomadro.service; "
"ss -lntp | grep -E '9300|4002' || true"
)
print(out)
# Force HOST + embed origins on 82
env, code = run(f"sudo cat {BASE}/.env")
if code != 0:
print("no .env")
return 1
lines = env.splitlines()
want = {
"HOST": "https://mirotalk.nomadro.cn",
"BIND_HOST": "127.0.0.1",
"PORT": "9300",
"TRUST_PROXY": "true",
"ALLOWED_EMBED_ORIGINS": (
"https://nomadro.cn,https://www.nomadro.cn,"
"https://nomadweb.nomadro.com,https://social.nomadro.cn,"
"http://localhost:3000,http://127.0.0.1:3000,"
"http://localhost:3001,http://127.0.0.1:3001"
),
"REDIRECT_URL": "https://nomadro.cn/social/meetup",
}
changed = False
keyed = {}
for i, line in enumerate(lines):
if "=" in line and not line.strip().startswith("#"):
k = line.split("=", 1)[0].strip()
keyed[k] = i
for k, v in want.items():
entry = f"{k}={v}"
if k in keyed:
if lines[keyed[k]] != entry:
lines[keyed[k]] = entry
changed = True
else:
lines.append(entry)
changed = True
if changed:
sftp = c.open_sftp()
with sftp.file("/tmp/mirotalk.env", "w") as f:
f.write("\n".join(lines) + "\n")
sftp.close()
run(f"sudo mv /tmp/mirotalk.env {BASE}/.env && sudo chmod 644 {BASE}/.env")
run("sudo systemctl restart mirotalk-p2p && sleep 2 && systemctl is-active mirotalk-p2p")
print("env updated + restarted")
else:
print("env already 82-only")
# Smoke
out, _ = run(
"curl -skI 'https://mirotalk.nomadro.cn/join?room=t&name=t&notify=0' | "
"tr -d '\\r' | grep -iE 'HTTP/|content-security-policy|server' | head -10; "
"echo ---; "
"curl -sk 'https://mirotalk.nomadro.cn/join?room=t&name=t&notify=0' | "
"grep -oE '正在进入活动厅|nomadro-speed.js|mirotalk.nomadro.com' | sort -u; "
"echo ---; "
"grep -E '^(HOST|ALLOWED_EMBED|BIND_HOST|PORT)=' /opt/nomadro-services/mirotalk/.env"
)
print(out)
# nginx vhost present?
out, _ = run(
"test -f /www/server/panel/vhost/nginx/mirotalk.nomadro.cn.conf && echo nginx_ok; "
"sudo nginx -t 2>&1 | tail -3"
)
print(out)
c.close()
return 0
if __name__ == "__main__":
raise SystemExit(main())