49 lines
2.1 KiB
Bash
49 lines
2.1 KiB
Bash
#!/usr/bin/env bash
|
||
# HEL-910 测试窗口:共享 CosyVoice TTS 9880 临时恢复/停回(按快照;精确 PID,禁 fuser -k)
|
||
# 用法: bash tts_ctl.sh start|stop|status|snapshot
|
||
set -u
|
||
BASE=/opt/cybergril-hel910
|
||
PIDF=$BASE/logs/tts9880.pid
|
||
SNAP=$BASE/snapshots/tts9880-before.txt
|
||
CC=/opt/voice-agent/cosyvoice
|
||
|
||
case "${1:-}" in
|
||
status)
|
||
if [ -f "$PIDF" ]; then P=$(cat "$PIDF"); kill -0 "$P" 2>/dev/null && echo "running pid $P (ours)" || echo "pid $P not alive"; else echo "not started by us"; fi
|
||
curl -s --max-time 3 http://127.0.0.1:9880/health && echo " <- health" || echo "health not answering"
|
||
exit 0 ;;
|
||
snapshot)
|
||
mkdir -p "$BASE/snapshots"
|
||
{ echo "ts=$(date -u +%FT%TZ)"; if curl -s --max-time 3 http://127.0.0.1:9880/health >/dev/null 2>&1; then echo "was=up"; else echo "was=down"; fi; ss -ltnp 2>/dev/null | grep ':9880 ' || echo "port9880=free"; } > "$SNAP"
|
||
cat "$SNAP" ;;
|
||
stop)
|
||
if [ -f "$PIDF" ]; then
|
||
P=$(cat "$PIDF")
|
||
kill "$P" 2>/dev/null; sleep 5
|
||
kill -0 "$P" 2>/dev/null && kill -9 "$P" 2>/dev/null
|
||
rm -f "$PIDF"
|
||
echo "tts stopped (pid $P)"
|
||
else
|
||
echo "not ours to stop (no pid file)"
|
||
fi
|
||
curl -s --max-time 3 http://127.0.0.1:9880/health >/dev/null 2>&1 && echo "WARN: 9880 still answering" || echo "9880 down" ;;
|
||
esac
|
||
|
||
# start (fallthrough)
|
||
if curl -s --max-time 3 http://127.0.0.1:9880/health >/dev/null 2>&1; then
|
||
echo "9880 already up — NOT ours, not touching"; exit 0
|
||
fi
|
||
if ss -ltn 2>/dev/null | grep -q ':9880 '; then echo "port 9880 occupied by non-healthy process — abort"; exit 1; fi
|
||
cd "$CC"
|
||
nohup "$CC/venv/bin/python" server.py >> "$CC/tts.log" 2>&1 &
|
||
echo $! > "$PIDF"
|
||
echo "tts starting (pid $(cat $PIDF)) — model load takes up to ~120s"
|
||
for i in $(seq 1 60); do
|
||
sleep 2
|
||
if curl -s --max-time 3 http://127.0.0.1:9880/health 2>/dev/null | grep -q '"ok"[[:space:]]*:[[:space:]]*true'; then
|
||
echo "OK: tts healthy after ~$((i*2))s"; exit 0
|
||
fi
|
||
kill -0 "$(cat $PIDF)" 2>/dev/null || { echo "FAIL: tts process died"; tail -10 "$CC/tts.log"; exit 1; }
|
||
done
|
||
echo "FAIL: tts not healthy in 120s"; tail -10 "$CC/tts.log"; exit 1
|