Spaces:
Running
Running
orztv
commited on
Commit
·
e16af67
1
Parent(s):
816d6fd
update
Browse files
run.sh
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
set -eo pipefail
|
3 |
+
|
4 |
+
# 导入环境变量
|
5 |
+
# source /home/pn/.env
|
6 |
+
|
7 |
+
# 错误处理函数
|
8 |
+
handle_error() {
|
9 |
+
echo "错误发生在第 $1 行"
|
10 |
+
exit 1
|
11 |
+
}
|
12 |
+
trap 'handle_error $LINENO' ERR
|
13 |
+
|
14 |
+
# 超时处理函数
|
15 |
+
timeout_handler() {
|
16 |
+
echo "操作超时"
|
17 |
+
exit 1
|
18 |
+
}
|
19 |
+
|
20 |
+
# 等待服务就绪的通用函数
|
21 |
+
wait_for_service() {
|
22 |
+
local service=$1
|
23 |
+
local host=$2
|
24 |
+
local port=$3
|
25 |
+
local timeout=${4:-$WAIT_TIMEOUT}
|
26 |
+
|
27 |
+
echo "等待 $service 就绪..."
|
28 |
+
local end=$((SECONDS + timeout))
|
29 |
+
|
30 |
+
while [ $SECONDS -lt $end ]; do
|
31 |
+
if nc -z "$host" "$port" >/dev/null 2>&1; then
|
32 |
+
echo "$service 已就绪"
|
33 |
+
return 0
|
34 |
+
fi
|
35 |
+
echo "尝试连接 $service at $host:$port..."
|
36 |
+
sleep 1
|
37 |
+
done
|
38 |
+
|
39 |
+
echo "$service 启动超时"
|
40 |
+
exit 1
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
# 检查服务状态
|
46 |
+
check_services() {
|
47 |
+
echo "检查服务状态..."
|
48 |
+
|
49 |
+
# 检查 Redis
|
50 |
+
echo "Redis 状态:"
|
51 |
+
redis-cli info | grep 'used_memory\|connected_clients\|total_connections_received'
|
52 |
+
|
53 |
+
# 检查 Qdrant
|
54 |
+
echo "Qdrant 状态:"
|
55 |
+
if curl -s http://localhost:6333/metrics >/dev/null; then
|
56 |
+
echo "Qdrant 运行正常"
|
57 |
+
curl -s http://localhost:6333/metrics
|
58 |
+
|
59 |
+
# 显示集合信息
|
60 |
+
echo "Qdrant 集合列表:"
|
61 |
+
curl -s http://localhost:6333/collections
|
62 |
+
else
|
63 |
+
echo "Qdrant 服务异常"
|
64 |
+
tail -n 10 /home/pn/.n8n/qdrant/qdrant.log
|
65 |
+
fi
|
66 |
+
}
|
67 |
+
|
68 |
+
# 主流程
|
69 |
+
main() {
|
70 |
+
current_time=$(date +"%Y-%m-%d %H:%M:%S")
|
71 |
+
echo "Starting services at $current_time"
|
72 |
+
# 启动服务
|
73 |
+
wait_for_service "PostgreSQL" "${DB_POSTGRESDB_HOST}" "${DB_POSTGRESDB_PORT}"
|
74 |
+
echo ""
|
75 |
+
check_services
|
76 |
+
|
77 |
+
echo "Starting deepseek-free-api... "
|
78 |
+
exec node /home/pn/deepseek-free-api/dist/index.js
|
79 |
+
}
|
80 |
+
|
81 |
+
# 执行主流程
|
82 |
+
main "$@"
|