Files
CyberGril/docs/rework/hel910/tools/api_ctl.sh
T

53 lines
1.7 KiB
Bash
Raw 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
# HEL-910 测试窗口:统一实例(8360 HTTP + 8361 HTTPS 同进程双入口)启动/停止
# 用法: bash api_ctl.sh start|stop|status (models.yaml 由调用方先摆好:failclosed 或 armed)
set -u
BASE=/opt/cybergril-hel910
CODE=$BASE/current
LOG=$BASE/logs/api.log
PIDF=$BASE/logs/api.pid
PAT='cybergril-hel910.*serve_dual_8360_8361'
stop() {
if [ -f "$PIDF" ]; then
P=$(cat "$PIDF")
if [ "$P" != "$$" ] && kill -0 "$P" 2>/dev/null; then kill "$P"; sleep 3; fi
if [ "$P" != "$$" ] && kill -0 "$P" 2>/dev/null; then kill -9 "$P"; fi
rm -f "$PIDF"
fi
for p in $(pgrep -f "$PAT"); do
[ "$p" = "$$" ] && continue
kill "$p" 2>/dev/null
done
echo "api stopped"
}
case "${1:-}" in
stop) stop; exit 0 ;;
status)
pgrep -af "$PAT" || echo "not running"
exit 0 ;;
esac
stop
cd "$CODE"
set -a
export CYBERGRIL_DB=$BASE/data/companion.db
export CYBERGRIL_SEMANTIC=stub
export CYBERGRIL_R2_ENABLED=1
export CYBERGRIL_MODELS=$BASE/etc/models.yaml
export CYBERGRIL_VOICE_CONFIG=$BASE/etc/voice.yaml
export CYBERGRIL_WEB=$CODE/web/dist
export PYTHONPATH=$CODE/src
set +a
nohup /opt/cybergril-hel879/current/.venv311/bin/python deploy/voice/serve_dual_8360_8361.py \
--http-port 8360 --https-port 8361 \
--cert /opt/cybergril-voice-certs/cybergril-voice.pem \
--key /opt/cybergril-voice-certs/cybergril-voice.key \
> "$LOG" 2>&1 &
echo $! > "$PIDF"
echo "api starting (pid $(cat $PIDF))"
sleep 6
curl -s --max-time 3 http://127.0.0.1:8360/api/health >/dev/null && echo "OK: 8360 healthy" || { echo "FAIL:"; tail -20 "$LOG"; exit 1; }
curl -sk --max-time 3 https://127.0.0.1:8361/api/health >/dev/null && echo "OK: 8361 healthy" || { echo "FAIL 8361:"; tail -20 "$LOG"; exit 1; }