Wire Taro social pages to social_svc (Centrifugo + live RTMP), drop multi-channel chat chrome, and add weapp WXSS sanitize/deploy helpers. Co-authored-by: Cursor <cursoragent@cursor.com>
133 lines
4.1 KiB
Python
133 lines
4.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy SRS (RTMP/FLV) + social live API + nginx /live/ on 82."""
|
|
from __future__ import annotations
|
|
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
REPO = Path(__file__).resolve().parents[3]
|
|
HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805"
|
|
REMOTE_LIVE = "/opt/nomadro-services/live"
|
|
REMOTE_SOCIAL = "/var/www/nomadro.cn/apps/api/services/social_svc"
|
|
|
|
|
|
def sftp_put(sftp, local: Path, remote: str) -> None:
|
|
data = local.read_bytes()
|
|
with sftp.file(remote, "wb") as rf:
|
|
rf.write(data)
|
|
print(f"up {remote} ({len(data)}B)", flush=True)
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(
|
|
HOST,
|
|
username=USER,
|
|
password=PASS,
|
|
timeout=60,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
sftp = c.open_sftp()
|
|
|
|
# SRS conf + nginx snippet
|
|
for cmd in (
|
|
f"sudo mkdir -p {REMOTE_LIVE}",
|
|
f"sudo chown ubuntu:ubuntu {REMOTE_LIVE}",
|
|
):
|
|
c.exec_command(cmd, timeout=30)
|
|
|
|
time.sleep(0.3)
|
|
sftp_put(sftp, REPO / "deploy/social/live/srs.conf", f"{REMOTE_LIVE}/srs.conf")
|
|
sftp_put(
|
|
sftp,
|
|
REPO / "deploy/social/live/nginx-live.conf",
|
|
f"{REMOTE_LIVE}/nginx-live.conf",
|
|
)
|
|
|
|
# social_svc live modules
|
|
files = [
|
|
"config.py",
|
|
"live.py",
|
|
"realtime.py",
|
|
"routers/api.py",
|
|
]
|
|
for rel in files:
|
|
local = REPO / "apps/api/services/social_svc" / rel
|
|
remote = f"/tmp/social_{rel.replace('/', '_')}"
|
|
sftp_put(sftp, local, remote)
|
|
|
|
sftp.close()
|
|
|
|
remote_sh = r"""
|
|
set -e
|
|
LIVE=/opt/nomadro-services/live
|
|
SVC=/var/www/nomadro.cn/apps/api/services/social_svc
|
|
|
|
# --- API files ---
|
|
sudo cp /tmp/social_config.py "$SVC/config.py"
|
|
sudo cp /tmp/social_live.py "$SVC/live.py"
|
|
sudo cp /tmp/social_realtime.py "$SVC/realtime.py"
|
|
sudo cp /tmp/social_routers_api.py "$SVC/routers/api.py"
|
|
sudo chown -R www-data:www-data "$SVC" 2>/dev/null || sudo chown -R ubuntu:ubuntu "$SVC"
|
|
|
|
# --- env ---
|
|
if ! grep -q LIVE_RTMP_PUSH_BASE /etc/nomadro/centrifugo.env 2>/dev/null; then
|
|
sudo tee -a /etc/nomadro/centrifugo.env >/dev/null <<'EOF'
|
|
LIVE_RTMP_PUSH_BASE=rtmp://82.157.112.245/live
|
|
LIVE_HTTP_PLAY_BASE=https://nomadro.cn/live
|
|
LIVE_MAX_PEERS=6
|
|
LIVE_PEER_TTL_SEC=45
|
|
EOF
|
|
fi
|
|
|
|
# --- SRS docker ---
|
|
if ! sudo docker ps -a --format '{{.Names}}' | grep -qx nomadro-srs; then
|
|
sudo docker run -d --name nomadro-srs --restart unless-stopped \
|
|
-p 1935:1935 -p 127.0.0.1:1985:1985 \
|
|
-v "$LIVE/srs.conf:/usr/local/srs/conf/srs.conf:ro" \
|
|
ossrs/srs:5 \
|
|
./objs/srs -c conf/srs.conf
|
|
else
|
|
sudo docker start nomadro-srs || true
|
|
sudo docker restart nomadro-srs || true
|
|
fi
|
|
|
|
# --- nginx Baota extension (beat Next catch-all with ^~) ---
|
|
EXT_DIR=/www/server/panel/vhost/nginx/extension/www.nomadro.cn
|
|
sudo mkdir -p "$EXT_DIR"
|
|
sudo cp "$LIVE/nginx-live.conf" "$EXT_DIR/live-flv.conf"
|
|
sudo nginx -t && sudo systemctl reload nginx || echo 'nginx reload skipped'
|
|
|
|
# open rtmp if ufw
|
|
sudo ufw allow 1935/tcp || true
|
|
|
|
sudo systemctl restart nomadro-social
|
|
sleep 2
|
|
systemctl is-active nomadro-social
|
|
sudo docker ps --filter name=nomadro-srs --format '{{.Names}} {{.Status}} {{.Ports}}'
|
|
curl -sk --max-time 5 https://nomadro.cn/api/social/v1/health | head -c 300; echo
|
|
curl -sk --max-time 8 -X POST 'https://nomadro.cn/api/social/v1/live/rooms/smoke/join' \
|
|
-H 'Content-Type: application/json' -H 'X-Social-Guest-Id: smoke_peer_1' \
|
|
-d '{"nick":"测试"}' | head -c 500; echo
|
|
ss -lntp | grep -E '1935|1985' || true
|
|
"""
|
|
_, stdout, _ = c.exec_command(remote_sh, timeout=240, get_pty=True)
|
|
while not stdout.channel.exit_status_ready():
|
|
if stdout.channel.recv_ready():
|
|
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
|
|
time.sleep(0.05)
|
|
while stdout.channel.recv_ready():
|
|
print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True)
|
|
code = stdout.channel.recv_exit_status()
|
|
print(f"[exit {code}]", flush=True)
|
|
c.close()
|
|
return code
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|