51 lines
1.5 KiB
Bash
Executable File
51 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# 模型路由自启动脚本
|
|
# 确保 OpenClaw Gateway 监听 18789,路由服务监听 18799
|
|
|
|
LOG_FILE="/root/.openclaw/workspace/memory/router.log"
|
|
ROUTER_PID_FILE="/tmp/model_router.pid"
|
|
|
|
start_router() {
|
|
if [ -f "$ROUTER_PID_FILE" ] && kill -0 $(cat "$ROUTER_PID_FILE") 2>/dev/null; then
|
|
echo "路由已在运行 (PID: $(cat $ROUTER_PID_FILE))"
|
|
return 0
|
|
fi
|
|
|
|
cd /root/.openclaw/workspace/models
|
|
nohup python3 model_router.py >> "$LOG_FILE" 2>&1 &
|
|
echo $! > "$ROUTER_PID_FILE"
|
|
sleep 2
|
|
|
|
if kill -0 $(cat "$ROUTER_PID_FILE") 2>/dev/null; then
|
|
echo "路由启动成功 (PID: $(cat $ROUTER_PID_FILE))"
|
|
else
|
|
echo "路由启动失败,查看日志: $LOG_FILE"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
stop_router() {
|
|
if [ -f "$ROUTER_PID_FILE" ]; then
|
|
kill $(cat "$ROUTER_PID_FILE") 2>/dev/null
|
|
rm -f "$ROUTER_PID_FILE"
|
|
echo "路由已停止"
|
|
fi
|
|
}
|
|
|
|
status_router() {
|
|
if [ -f "$ROUTER_PID_FILE" ] && kill -0 $(cat "$ROUTER_PID_FILE") 2>/dev/null; then
|
|
echo "路由运行中 (PID: $(cat $ROUTER_PID_FILE))"
|
|
curl -s http://127.0.0.1:18799/ 2>/dev/null | python3 -c "import sys,json; d=json.load(sys.stdin); print('端点:', len(d.get('endpoints',[])), '个')" 2>/dev/null || true
|
|
else
|
|
echo "路由未运行"
|
|
fi
|
|
}
|
|
|
|
case "$1" in
|
|
start) start_router ;;
|
|
stop) stop_router ;;
|
|
status) status_router ;;
|
|
restart) stop_router; start_router ;;
|
|
*) echo "用法: $0 {start|stop|status|restart}" ;;
|
|
esac
|