Files

60 lines
2.8 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 修复语音通话“门号不一致”(信令通、媒体不通)问题。
# 根因:LiveKit 的 config/livekit.yaml 里媒体端口(7881/7882)与宿主实际映射(17881/17882)不一致,
# 导致 LiveKit 向客户端宣告的媒体地址连不上。
# 修复:统一 .env / config/livekit.yaml / docker-compose.yaml 三处端口为 17880/17881/17882
# 只重启 livekit 容器。
#
# 用法(在服务器仓库目录里执行,且已 git pull 到含本修复的版本):
# ./scripts/fix-livekit-ports.sh
#
# 该脚本幂等,可重复执行;会先备份再改动,失败可回退。
set -euo pipefail
cd "$(dirname "$0")/.."
TS="$(date +%Y%m%d-%H%M%S)"
BK="backup-livekit-ports-$TS"
mkdir -p "$BK"
echo "==> 备份当前配置到 $BK/"
for f in .env config/livekit.yaml docker-compose.yaml; do
[ -f "$f" ] && cp -p "$f" "$BK/$(basename "$f")"
done
[ -f "$BK/.env" ] || echo "(未找到 .env,跳过备份)"
# 1. 校验仓库文件已含修复(config/livekit.yaml 端口应为 17880/17881/17882
grep -q '^port: 17880' config/livekit.yaml || { echo "✗ config/livekit.yaml 未包含 port: 17880,请先 git pull 更新仓库后再执行本脚本"; exit 1; }
grep -q 'tcp_port: 17881' config/livekit.yaml || { echo "✗ config/livekit.yaml 未包含 tcp_port: 17881"; exit 1; }
grep -q 'udp_port: 17882' config/livekit.yaml || { echo "✗ config/livekit.yaml 未包含 udp_port: 17882"; exit 1; }
# 2. 对齐 .env 三个端口
if [ ! -f .env ]; then
cp .env.example .env
echo "==> 未找到 .env,已从 .env.example 生成"
fi
sed -i 's|^LIVEKIT_PORT=.*|LIVEKIT_PORT=17880|' .env
sed -i 's|^LIVEKIT_RTC_TCP_PORT=.*|LIVEKIT_RTC_TCP_PORT=17881|' .env
sed -i 's|^LIVEKIT_RTC_UDP_PORT=.*|LIVEKIT_RTC_UDP_PORT=17882|' .env
# 若这三行原本不存在,则追加
grep -q '^LIVEKIT_PORT=' .env || echo 'LIVEKIT_PORT=17880' >> .env
grep -q '^LIVEKIT_RTC_TCP_PORT=' .env || echo 'LIVEKIT_RTC_TCP_PORT=17881' >> .env
grep -q '^LIVEKIT_RTC_UDP_PORT=' .env || echo 'LIVEKIT_RTC_UDP_PORT=17882' >> .env
echo "==> .env 三个端口已设为 17880/17881/17882"
# 3. 只重建 livekit 容器(不动其它服务)
docker compose up -d --force-recreate livekit
# 4. 校验
echo "==> 等待 livekit 就绪..."
sleep 3
docker compose ps livekit
echo
echo "==> 请确认防火墙放通 17880/TCP、17881/TCP、17882/UDP(默认已在本机监听):"
ss -tlnp 2>/dev/null | grep -E ':(17880|17881)' || true
ss -ulnp 2>/dev/null | grep ':17882' || true
echo
echo "==> 完成。回退方法(用刚才的备份恢复旧配置):"
echo " cp $BK/livekit.yaml config/livekit.yaml 2>/dev/null"
echo " cp $BK/docker-compose.yaml docker-compose.yaml 2>/dev/null"
echo " cp $BK/.env .env 2>/dev/null"
echo " docker compose up -d --force-recreate livekit"