-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_all_services.sh
More file actions
executable file
·288 lines (259 loc) · 11.8 KB
/
Copy pathstart_all_services.sh
File metadata and controls
executable file
·288 lines (259 loc) · 11.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/bin/bash
# LangGraph 代码助手 - 启动所有服务脚本
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ ║"
echo "║ 启动 LangGraph 代码助手所有服务 ║"
echo "║ ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
# 颜色定义
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# 日志目录
LOG_DIR="logs"
mkdir -p $LOG_DIR
# 解析命令行参数
LLM_MODE="real" # 默认使用真实 LLM (real_llm_server.py)
while [[ $# -gt 0 ]]; do
case $1 in
--mock)
LLM_MODE="mock"
shift
;;
--buggy)
LLM_MODE="buggy"
shift
;;
--help)
echo "用法: $0 [选项]"
echo ""
echo "选项:"
echo " --mock 使用 simple_llm_server.py (模拟 LLM,不调用真实 API)"
echo " --buggy 使用 buggy_llm_server.py (故意返回错误代码,用于测试)"
echo " 默认 使用 real_llm_server.py (调用真实 Kimi API)"
echo ""
echo "示例:"
echo " $0 # 使用真实 LLM (Kimi API)"
echo " $0 --mock # 使用模拟 LLM"
echo " $0 --buggy # 使用 Buggy LLM (测试错误处理)"
exit 0
;;
*)
echo "未知选项: $1"
echo "使用 --help 查看帮助"
exit 1
;;
esac
done
# 检查端口是否被占用
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1 ; then
return 0 # 端口被占用
else
return 1 # 端口空闲
fi
}
# 等待服务启动
wait_for_service() {
local host=$1
local port=$2
local service_name=$3
local max_wait=30
local count=0
echo -n " 等待 $service_name 启动..."
while [ $count -lt $max_wait ]; do
if nc -z $host $port 2>/dev/null || curl -s http://$host:$port/health > /dev/null 2>&1; then
echo -e " ${GREEN}✓${NC}"
return 0
fi
sleep 1
count=$((count + 1))
echo -n "."
done
echo -e " ${RED}✗ 超时${NC}"
return 1
}
# 检查 Redis
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "1️⃣ 检查 Redis 服务"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if check_port 6379; then
echo -e " ${GREEN}✓${NC} Redis 已在运行 (localhost:6379)"
else
echo -e " ${YELLOW}⚠${NC} Redis 未运行,尝试启动..."
# 检查是否有 Docker
if command -v docker &> /dev/null; then
echo " 使用 Docker 启动 Redis..."
docker run -d --name redis-langgraph -p 6379:6379 redis:latest > /dev/null 2>&1
if [ $? -eq 0 ]; then
wait_for_service localhost 6379 "Redis"
else
echo -e " ${RED}✗${NC} Docker 启动失败,请手动启动 Redis"
echo " 命令: redis-server 或 docker run -d -p 6379:6379 redis:latest"
fi
else
echo -e " ${RED}✗${NC} 请手动启动 Redis"
echo " 命令: redis-server"
fi
fi
# 启动 LLM 服务器
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "2️⃣ 启动 LLM 服务器 (localhost:8000)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if check_port 8000; then
echo -e " ${YELLOW}⚠${NC} 端口 8000 已被占用,跳过启动"
else
case $LLM_MODE in
mock)
echo -e " ${BLUE}使用模式: Mock LLM (simple_llm_server.py)${NC}"
python simple_llm_server.py > $LOG_DIR/llm_server.log 2>&1 &
;;
buggy)
echo -e " ${YELLOW}使用模式: Buggy LLM (buggy_llm_server.py) - 用于测试${NC}"
python buggy_llm_server.py > $LOG_DIR/llm_server.log 2>&1 &
;;
*)
echo -e " ${GREEN}使用模式: Real LLM (real_llm_server.py - Kimi API)${NC}"
python real_llm_server.py > $LOG_DIR/llm_server.log 2>&1 &
;;
esac
LLM_PID=$!
echo $LLM_PID > $LOG_DIR/llm_server.pid
wait_for_service localhost 8000 "LLM Server"
fi
# 启动 Coder 服务
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "3️⃣ 启动 Coder 服务 (localhost:8001)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if check_port 8001; then
echo -e " ${YELLOW}⚠${NC} 端口 8001 已被占用,跳过启动"
else
echo " 启动 Coder 服务..."
python local_llm_service_restful.py --service coder --port 8001 --llm-url http://localhost:8000 > $LOG_DIR/coder.log 2>&1 &
CODER_PID=$!
echo $CODER_PID > $LOG_DIR/coder.pid
wait_for_service localhost 8001 "Coder Service"
fi
# 启动 Checker 服务
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "4️⃣ 启动 Checker 服务 (localhost:8002)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if check_port 8002; then
echo -e " ${YELLOW}⚠${NC} 端口 8002 已被占用,跳过启动"
else
echo " 启动 Checker 服务..."
python local_llm_service_restful.py --service checker --port 8002 --llm-url http://localhost:8000 > $LOG_DIR/checker.log 2>&1 &
CHECKER_PID=$!
echo $CHECKER_PID > $LOG_DIR/checker.pid
wait_for_service localhost 8002 "Checker Service"
fi
# 启动 Debugger 服务
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "5️⃣ 启动 Debugger 服务 (localhost:8003)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if check_port 8003; then
echo -e " ${YELLOW}⚠${NC} 端口 8003 已被占用,跳过启动"
else
echo " 启动 Debugger 服务..."
python local_llm_service_restful.py --service debugger --port 8003 --llm-url http://localhost:8000 > $LOG_DIR/debugger.log 2>&1 &
DEBUGGER_PID=$!
echo $DEBUGGER_PID > $LOG_DIR/debugger.pid
wait_for_service localhost 8003 "Debugger Service"
fi
# 启动 Tool 服务
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "6️⃣ 启动 Tool 服务 (localhost:8004)"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
if check_port 8004; then
echo -e " ${YELLOW}⚠${NC} 端口 8004 已被占用,跳过启动"
else
echo " 启动 Tool 服务..."
python local_llm_service_restful.py --service tool --port 8004 --llm-url http://localhost:8000 > $LOG_DIR/tool.log 2>&1 &
TOOL_PID=$!
echo $TOOL_PID > $LOG_DIR/tool.pid
wait_for_service localhost 8004 "Tool Service"
fi
# 总结
echo ""
echo "╔══════════════════════════════════════════════════════════╗"
echo "║ 🎉 启动完成 ║"
echo "╚══════════════════════════════════════════════════════════╝"
echo ""
echo "📋 服务状态:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
services=(
"Redis:6379"
"LLM_Server:8000"
"Coder:8001"
"Checker:8002"
"Debugger:8003"
"Tool:8004"
)
for service in "${services[@]}"; do
IFS=':' read -r name port <<< "$service"
if check_port $port; then
echo -e " ${GREEN}✓${NC} $name (localhost:$port)"
else
echo -e " ${RED}✗${NC} $name (localhost:$port)"
fi
done
echo ""
echo "🌐 LLM 模式:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
case $LLM_MODE in
mock)
echo -e " ${BLUE}Mock LLM${NC} - 使用预定义响应,不调用 API"
;;
buggy)
echo -e " ${YELLOW}Buggy LLM${NC} - 故意返回错误代码,用于测试错误处理"
;;
*)
echo -e " ${GREEN}Real LLM${NC} - 调用 Moonshot Kimi API (kimi-k2-turbo-preview)"
echo " API Key: sk-4VF7qW5HsuXjgOwiCl4boalx8HzY5U2HBSF8mIFPD8Hz8SLM"
;;
esac
echo ""
echo "📝 日志文件:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " • LLM Server: $LOG_DIR/llm_server.log"
echo " • Coder: $LOG_DIR/coder.log"
echo " • Checker: $LOG_DIR/checker.log"
echo " • Debugger: $LOG_DIR/debugger.log"
echo " • Tool: $LOG_DIR/tool.log"
echo ""
echo "🧪 测试命令:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " # 健康检查所有服务"
echo " for port in 8000 8001 8002 8003 8004; do"
echo " curl -s http://localhost:\$port/health | python -m json.tool"
echo " done"
echo ""
echo " # 运行端到端测试"
echo " python test/test_real_llm.py --mode e2e"
echo ""
echo " # 测试单个服务"
echo " python test/test_real_llm.py --mode single"
echo ""
echo " # 测试错误处理(需要使用 --buggy 模式启动)"
echo " python test/test_with_buggy_llm.py"
echo ""
echo "⚠️ 停止所有服务:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " ./stop_all_services.sh"
echo ""
echo "💡 提示:"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " • 查看实时日志: tail -f logs/[service_name].log"
echo " • 检查服务状态: curl http://localhost:[port]/health"
echo " • 重置 Buggy LLM 计数器: curl -X POST http://localhost:8000/reset"
echo ""