Spaces:
Running
Running
File size: 1,821 Bytes
e16af67 |
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 |
#!/bin/bash
set -eo pipefail
# 导入环境变量
# source /home/pn/.env
# 错误处理函数
handle_error() {
echo "错误发生在第 $1 行"
exit 1
}
trap 'handle_error $LINENO' ERR
# 超时处理函数
timeout_handler() {
echo "操作超时"
exit 1
}
# 等待服务就绪的通用函数
wait_for_service() {
local service=$1
local host=$2
local port=$3
local timeout=${4:-$WAIT_TIMEOUT}
echo "等待 $service 就绪..."
local end=$((SECONDS + timeout))
while [ $SECONDS -lt $end ]; do
if nc -z "$host" "$port" >/dev/null 2>&1; then
echo "$service 已就绪"
return 0
fi
echo "尝试连接 $service at $host:$port..."
sleep 1
done
echo "$service 启动超时"
exit 1
}
# 检查服务状态
check_services() {
echo "检查服务状态..."
# 检查 Redis
echo "Redis 状态:"
redis-cli info | grep 'used_memory\|connected_clients\|total_connections_received'
# 检查 Qdrant
echo "Qdrant 状态:"
if curl -s http://localhost:6333/metrics >/dev/null; then
echo "Qdrant 运行正常"
curl -s http://localhost:6333/metrics
# 显示集合信息
echo "Qdrant 集合列表:"
curl -s http://localhost:6333/collections
else
echo "Qdrant 服务异常"
tail -n 10 /home/pn/.n8n/qdrant/qdrant.log
fi
}
# 主流程
main() {
current_time=$(date +"%Y-%m-%d %H:%M:%S")
echo "Starting services at $current_time"
# 启动服务
wait_for_service "PostgreSQL" "${DB_POSTGRESDB_HOST}" "${DB_POSTGRESDB_PORT}"
echo ""
check_services
echo "Starting deepseek-free-api... "
exec node /home/pn/deepseek-free-api/dist/index.js
}
# 执行主流程
main "$@"
|