#!/bin/bash # 大模型API中转系统 启动/停止/状态脚本 # 用法: ./start.sh [start|stop|restart|status] 默认 start cd "$(dirname "$0")" PORT=16003 APP=app.py PYTHON=/home/hz1/miniconda3/envs/openclaw/bin/python3 PID_FILE=data/proxy.pid mkdir -p data logs if [ ! -x "$PYTHON" ]; then PYTHON=python3 fi start() { if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then echo "LLM Proxy 已在运行 (PID $(cat "$PID_FILE"), 端口 $PORT)" return 0 fi nohup "$PYTHON" "$APP" > logs/start.log 2>&1 & echo $! > "$PID_FILE" sleep 1.5 if kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then echo "✅ LLM Proxy 已启动 (PID $(cat "$PID_FILE"))" echo " 前台API: http://:$PORT/v1/chat/completions" echo " 后台管理: http://:$PORT/admin" else echo "❌ 启动失败,查看日志: logs/start.log" tail -20 logs/start.log return 1 fi } stop() { if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then kill "$(cat "$PID_FILE")" rm -f "$PID_FILE" echo "🛑 LLM Proxy 已停止" else echo "LLM Proxy 未在运行" fi } status() { if [ -f "$PID_FILE" ] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then echo "✅ LLM Proxy 运行中 (PID $(cat "$PID_FILE"), 端口 $PORT)" else echo "❌ LLM Proxy 未运行" fi } case "${1:-start}" in start) start ;; stop) stop ;; restart) stop; sleep 1; start ;; status) status ;; *) echo "用法: $0 [start|stop|restart|status]"; exit 1 ;; esac