sam12345324 commited on
Commit
6a109e7
·
verified ·
1 Parent(s): fd7cf14

Update run.sh

Browse files
Files changed (1) hide show
  1. run.sh +33 -88
run.sh CHANGED
@@ -50,10 +50,8 @@ start_redis() {
50
  exit 1
51
  fi
52
 
53
- # 设置 Redis 配置
54
  redis-cli config set maxmemory 512mb
55
  redis-cli config set maxmemory-policy allkeys-lru
56
- echo ""
57
  echo "Redis server started successfully"
58
  echo ""
59
  }
@@ -62,17 +60,10 @@ start_redis() {
62
  start_qdrant() {
63
  echo "Starting Qdrant server..."
64
 
65
- # 确保目录存在并有正确的权限
66
- mkdir -p /home/pn/.n8n/qdrant/storage
67
- mkdir -p /home/pn/.n8n/qdrant/config
68
- mkdir -p /home/pn/.n8n/qdrant/snapshots
69
- mkdir -p /home/pn/.n8n/qdrant/logs
70
-
71
- # 设置正确的权限
72
  chmod -R 755 /home/pn/.n8n/qdrant
73
  chown -R pn:pn /home/pn/.n8n/qdrant
74
-
75
- # 创建 Qdrant 配置文件
76
  cat > /home/pn/.n8n/qdrant/config/config.yaml <<EOF
77
  service:
78
  host: 0.0.0.0
@@ -116,24 +107,19 @@ logger:
116
  telemetry_disabled: true
117
  EOF
118
 
119
- # 确保配置文件有正确的权限
120
  chmod 644 /home/pn/.n8n/qdrant/config/config.yaml
121
-
122
- # 使用配置文件启动 Qdrant
123
  qdrant --config-path /home/pn/.n8n/qdrant/config/config.yaml > /home/pn/.n8n/qdrant/logs/startup.log 2>&1 &
124
-
125
- # 等待 Qdrant 启动
126
  local timeout=30
127
  local end=$((SECONDS + timeout))
128
-
129
  while [ $SECONDS -lt $end ]; do
130
  if curl -s http://localhost:6333/health >/dev/null; then
131
  echo "Qdrant server started successfully"
132
-
133
- # 预创建常用集合
134
  echo "Creating default collections..."
135
-
136
- # 创建文本向量集合 (768维,适用于多数文本嵌入模型)
137
  curl -X PUT 'http://localhost:6333/collections/text_vectors' \
138
  -H 'Content-Type: application/json' \
139
  -d '{
@@ -141,84 +127,45 @@ EOF
141
  "size": 768,
142
  "distance": "Cosine",
143
  "on_disk": true
144
- },
145
- "optimizers_config": {
146
- "default_segment_number": 2,
147
- "indexing_threshold": 20000,
148
- "memmap_threshold": 10000
149
- },
150
- "hnsw_config": {
151
- "m": 16,
152
- "ef_construct": 100,
153
- "full_scan_threshold": 10000,
154
- "max_indexing_threads": 0,
155
- "on_disk": true
156
- },
157
- "init_from": {
158
- "collection_name": "text_vectors"
159
  }
160
  }'
161
-
162
- # 创建图像向量集合 (512维,适用于多数图像嵌入模型)
163
  curl -X PUT 'http://localhost:6333/collections/image_vectors' \
164
  -H 'Content-Type: application/json' \
165
  -d '{
166
  "vectors": {
167
  "size": 512,
168
  "distance": "Cosine"
169
- },
170
- "optimizers_config": {
171
- "default_segment_number": 2,
172
- "indexing_threshold": 20000
173
- },
174
- "hnsw_config": {
175
- "m": 16,
176
- "ef_construct": 100,
177
- "full_scan_threshold": 10000
178
  }
179
  }'
180
-
181
- # 创建通用向量集合 (1536维,适用于 OpenAI 的嵌入模型)
182
  curl -X PUT 'http://localhost:6333/collections/openai_vectors' \
183
  -H 'Content-Type: application/json' \
184
  -d '{
185
  "vectors": {
186
  "size": 1536,
187
  "distance": "Cosine"
188
- },
189
- "optimizers_config": {
190
- "default_segment_number": 2,
191
- "indexing_threshold": 20000
192
- },
193
- "hnsw_config": {
194
- "m": 16,
195
- "ef_construct": 100,
196
- "full_scan_threshold": 10000
197
  }
198
  }'
199
-
200
- # 验证集合创建状态并输出详细信息
201
  echo -e "\nVerifying collections:"
202
  curl -s 'http://localhost:6333/collections' | jq '.'
203
-
204
- # 测试连接
205
  echo -e "\nTesting Qdrant connection:"
206
  curl -v http://localhost:6333/health
207
-
208
  return 0
209
  fi
 
210
  echo "Waiting for Qdrant to start..."
211
  sleep 1
212
-
213
- # 检查是否有错误日志
214
  if grep -i "error" /home/pn/.n8n/qdrant/logs/startup.log >/dev/null 2>&1; then
215
  echo "Error found in Qdrant logs:"
216
  tail -n 10 /home/pn/.n8n/qdrant/logs/startup.log
217
  fi
218
  done
219
-
220
  echo "Failed to start Qdrant server"
221
- echo "Last 10 lines of Qdrant log:"
222
  tail -n 10 /home/pn/.n8n/qdrant/logs/startup.log
223
  exit 1
224
  }
@@ -226,18 +173,14 @@ EOF
226
  # 检查服务状态
227
  check_services() {
228
  echo "检查服务状态..."
229
-
230
- # 检查 Redis
231
  echo "Redis 状态:"
232
  redis-cli info | grep 'used_memory\|connected_clients\|total_connections_received'
233
-
234
- # 检查 Qdrant
235
  echo "Qdrant 状态:"
236
  if curl -s http://localhost:6333/metrics >/dev/null; then
237
  echo "Qdrant 运行正常"
238
  curl -s http://localhost:6333/metrics
239
-
240
- # 显示集合信息
241
  echo "Qdrant 集合列表:"
242
  curl -s http://localhost:6333/collections
243
  else
@@ -249,32 +192,34 @@ check_services() {
249
  # 主流程
250
  main() {
251
  current_time=$(date +"%Y-%m-%d %H:%M:%S")
252
- echo "Starting services at $current_time"
253
-
254
- # 输出配置信息
255
  echo "Database Configuration:"
256
- echo "Host: ${DB_POSTGRESDB_HOST}"
257
- echo "Port: ${DB_POSTGRESDB_PORT}"
258
- echo "User: ${DB_POSTGRESDB_USER}"
259
- echo "Database: ${DB_POSTGRESDB_DATABASE}"
260
  echo "Type: ${DB_TYPE}"
261
-
262
- # 启动服务
263
- wait_for_service "PostgreSQL" "${DB_POSTGRESDB_HOST}" "${DB_POSTGRESDB_PORT}"
 
 
 
 
 
 
264
  echo ""
265
  start_redis
266
  echo ""
267
  start_qdrant
268
  echo ""
269
  check_services
270
-
271
- # 设置 N8N 环境变量
272
- source /home/pn/n8n/config/n8n_env.sh
273
-
 
 
274
  echo ""
275
  echo "Starting n8n..."
276
  exec n8n start
277
  }
278
 
279
- # 执行主流程
280
  main "$@"
 
50
  exit 1
51
  fi
52
 
 
53
  redis-cli config set maxmemory 512mb
54
  redis-cli config set maxmemory-policy allkeys-lru
 
55
  echo "Redis server started successfully"
56
  echo ""
57
  }
 
60
  start_qdrant() {
61
  echo "Starting Qdrant server..."
62
 
63
+ mkdir -p /home/pn/.n8n/qdrant/{storage,config,snapshots,logs}
 
 
 
 
 
 
64
  chmod -R 755 /home/pn/.n8n/qdrant
65
  chown -R pn:pn /home/pn/.n8n/qdrant
66
+
 
67
  cat > /home/pn/.n8n/qdrant/config/config.yaml <<EOF
68
  service:
69
  host: 0.0.0.0
 
107
  telemetry_disabled: true
108
  EOF
109
 
 
110
  chmod 644 /home/pn/.n8n/qdrant/config/config.yaml
111
+
 
112
  qdrant --config-path /home/pn/.n8n/qdrant/config/config.yaml > /home/pn/.n8n/qdrant/logs/startup.log 2>&1 &
113
+
 
114
  local timeout=30
115
  local end=$((SECONDS + timeout))
116
+
117
  while [ $SECONDS -lt $end ]; do
118
  if curl -s http://localhost:6333/health >/dev/null; then
119
  echo "Qdrant server started successfully"
120
+
 
121
  echo "Creating default collections..."
122
+
 
123
  curl -X PUT 'http://localhost:6333/collections/text_vectors' \
124
  -H 'Content-Type: application/json' \
125
  -d '{
 
127
  "size": 768,
128
  "distance": "Cosine",
129
  "on_disk": true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  }
131
  }'
132
+
 
133
  curl -X PUT 'http://localhost:6333/collections/image_vectors' \
134
  -H 'Content-Type: application/json' \
135
  -d '{
136
  "vectors": {
137
  "size": 512,
138
  "distance": "Cosine"
 
 
 
 
 
 
 
 
 
139
  }
140
  }'
141
+
 
142
  curl -X PUT 'http://localhost:6333/collections/openai_vectors' \
143
  -H 'Content-Type: application/json' \
144
  -d '{
145
  "vectors": {
146
  "size": 1536,
147
  "distance": "Cosine"
 
 
 
 
 
 
 
 
 
148
  }
149
  }'
150
+
 
151
  echo -e "\nVerifying collections:"
152
  curl -s 'http://localhost:6333/collections' | jq '.'
153
+
 
154
  echo -e "\nTesting Qdrant connection:"
155
  curl -v http://localhost:6333/health
 
156
  return 0
157
  fi
158
+
159
  echo "Waiting for Qdrant to start..."
160
  sleep 1
161
+
 
162
  if grep -i "error" /home/pn/.n8n/qdrant/logs/startup.log >/dev/null 2>&1; then
163
  echo "Error found in Qdrant logs:"
164
  tail -n 10 /home/pn/.n8n/qdrant/logs/startup.log
165
  fi
166
  done
167
+
168
  echo "Failed to start Qdrant server"
 
169
  tail -n 10 /home/pn/.n8n/qdrant/logs/startup.log
170
  exit 1
171
  }
 
173
  # 检查服务状态
174
  check_services() {
175
  echo "检查服务状态..."
176
+
 
177
  echo "Redis 状态:"
178
  redis-cli info | grep 'used_memory\|connected_clients\|total_connections_received'
179
+
 
180
  echo "Qdrant 状态:"
181
  if curl -s http://localhost:6333/metrics >/dev/null; then
182
  echo "Qdrant 运行正常"
183
  curl -s http://localhost:6333/metrics
 
 
184
  echo "Qdrant 集合列表:"
185
  curl -s http://localhost:6333/collections
186
  else
 
192
  # 主流程
193
  main() {
194
  current_time=$(date +"%Y-%m-%d %H:%M:%S")
195
+ echo "===== Application Startup at $current_time ====="
196
+
 
197
  echo "Database Configuration:"
 
 
 
 
198
  echo "Type: ${DB_TYPE}"
199
+
200
+ if [[ "$DB_TYPE" == "postgresdb" ]]; then
201
+ echo "Host: ${DB_POSTGRESDB_HOST}"
202
+ echo "Port: ${DB_POSTGRESDB_PORT}"
203
+ echo "User: ${DB_POSTGRESDB_USER}"
204
+ echo "Database: ${DB_POSTGRESDB_DATABASE}"
205
+ wait_for_service "PostgreSQL" "${DB_POSTGRESDB_HOST}" "${DB_POSTGRESDB_PORT}"
206
+ fi
207
+
208
  echo ""
209
  start_redis
210
  echo ""
211
  start_qdrant
212
  echo ""
213
  check_services
214
+
215
+ # 加载额外 n8n 环境变量(可选)
216
+ if [ -f /home/pn/n8n/config/n8n_env.sh ]; then
217
+ source /home/pn/n8n/config/n8n_env.sh
218
+ fi
219
+
220
  echo ""
221
  echo "Starting n8n..."
222
  exec n8n start
223
  }
224
 
 
225
  main "$@"