-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsearch-setup.sh
More file actions
executable file
·338 lines (287 loc) · 10.5 KB
/
Copy pathsearch-setup.sh
File metadata and controls
executable file
·338 lines (287 loc) · 10.5 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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#!/bin/bash
# Elasticsearch Search Setup Script for Rspamd Documentation
# This script helps you set up and manage the Elasticsearch search infrastructure
set -e
# Configuration
ELASTICSEARCH_URL="http://localhost:9200"
INDEX_NAME="rspamd-docs"
SITE_URL="http://localhost:3000"
BACKEND_URL="http://localhost:3001"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
DOCKER_COMPOSE="docker compose"
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_header() {
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}$1${NC}"
echo -e "${BLUE}========================================${NC}"
}
# Function to check if a service is running
check_service() {
local service_name=$1
local port=$2
if curl -s "http://localhost:$port" > /dev/null 2>&1; then
print_status "$service_name is running on port $port"
return 0
else
print_warning "$service_name is not running on port $port"
return 1
fi
}
# Function to wait for service to be ready
wait_for_service() {
local service_name=$1
local url=$2
local max_attempts=30
local attempt=1
print_status "Waiting for $service_name to be ready..."
while [ $attempt -le $max_attempts ]; do
if curl -s "$url" > /dev/null 2>&1; then
print_status "$service_name is ready!"
return 0
fi
echo -n "."
sleep 2
attempt=$((attempt + 1))
done
print_error "$service_name failed to start within $((max_attempts * 2)) seconds"
return 1
}
# Function to start services
start_services() {
print_header "Starting Elasticsearch Services"
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
print_error "Docker is not running. Please start Docker and try again."
exit 1
fi
# Start core services
print_status "Starting Elasticsearch, Kibana, and Search Backend..."
${DOCKER_COMPOSE} up -d elasticsearch kibana search-backend
# Wait for Search Backend to be ready (this will ensure Elasticsearch is also ready)
if ! wait_for_service "Search Backend" "$BACKEND_URL/health"; then
print_error "Failed to start Search Backend"
exit 1
fi
# Wait for Kibana to be ready
if ! wait_for_service "Kibana" "http://localhost:5601"; then
print_warning "Kibana might not be ready yet, but continuing..."
fi
print_status "Services started successfully!"
print_status "Search Backend: http://localhost:3001 (public API)"
print_status "Kibana: http://localhost:5601 (localhost admin access)"
print_status "Elasticsearch: Running internally (not exposed to host)"
}
# Function to start services with auto-indexing
start_with_auto_indexing() {
print_header "Starting Services with Auto-Indexing"
# Check if Docker is running
if ! docker info > /dev/null 2>&1; then
print_error "Docker is not running. Please start Docker and try again."
exit 1
fi
# Start all services including auto-indexer
print_status "Starting Elasticsearch, Kibana, Search Backend, and Auto-Indexer..."
${DOCKER_COMPOSE} --profile auto-indexing up -d
# Wait for Search Backend to be ready (this will ensure Elasticsearch is also ready)
if ! wait_for_service "Search Backend" "$BACKEND_URL/health"; then
print_error "Failed to start Search Backend"
exit 1
fi
print_status "Services with auto-indexing started successfully!"
print_status "Search Backend: http://localhost:3001 (public API)"
print_status "Kibana: http://localhost:5601 (localhost admin access)"
print_status "Elasticsearch: Running internally (not exposed to host)"
print_status "Auto-indexer will run every hour to keep the index updated"
}
# Function to stop services
stop_services() {
print_header "Stopping Elasticsearch Services"
print_status "Stopping all containers..."
${DOCKER_COMPOSE} down
print_status "Services stopped successfully!"
}
# Function to run indexer
run_indexer() {
print_header "Running Search Indexer"
# Check if Search Backend is running (this ensures Elasticsearch is also running)
if ! check_service "Search Backend" "3001"; then
print_error "Search Backend is not running. Please start it first with: $0 start"
exit 1
fi
# Check if Docusaurus dev server is running
if ! check_service "Docusaurus" "3000"; then
print_warning "Docusaurus dev server is not running on port 3000"
print_warning "You might want to start it with: npm start"
print_warning "Continuing with markdown file indexing only..."
fi
# Run the indexer using the indexing profile
print_status "Running indexer..."
${DOCKER_COMPOSE} --profile indexing run --rm search-indexer
print_status "Indexing completed!"
}
# Function to run lite indexer (without puppeteer)
run_lite_indexer() {
print_header "Running Lite Search Indexer (Markdown Only)"
# Check if Search Backend is running (this ensures Elasticsearch is also running)
if ! check_service "Search Backend" "3001"; then
print_error "Search Backend is not running. Please start it first with: $0 start"
exit 1
fi
print_status "Running lite indexer (no browser dependencies)..."
print_status "This will index markdown files only, skipping rendered pages"
${DOCKER_COMPOSE} --profile lite-indexing run --rm search-indexer-lite
print_status "Lite indexing completed!"
}
# Function to check status
check_status() {
print_header "Service Status Check"
# Check Docker
if docker info > /dev/null 2>&1; then
print_status "Docker is running"
else
print_error "Docker is not running"
fi
# Check services
check_service "Search Backend" "3001"
check_service "Kibana" "5601"
check_service "Docusaurus" "3000"
# Check index status via search backend
if curl -s "$BACKEND_URL/status" > /dev/null 2>&1; then
local status_response=$(curl -s "$BACKEND_URL/status")
local doc_count=$(echo "$status_response" | grep -o '"documentCount":[0-9]*' | cut -d: -f2)
if [ -n "$doc_count" ]; then
print_status "Index '$INDEX_NAME' exists with $doc_count documents"
else
print_warning "Index '$INDEX_NAME' status unclear"
fi
else
print_warning "Cannot check index status - search backend may not be ready"
fi
}
# Function to reset index
reset_index() {
print_header "Resetting Search Index"
# Check if Search Backend is running (this ensures Elasticsearch is also running)
if ! check_service "Search Backend" "3001"; then
print_error "Search Backend is not running. Please start it first with: $0 start"
exit 1
fi
print_status "Deleting existing index..."
docker exec rspamd-elasticsearch curl -X DELETE "http://localhost:9200/$INDEX_NAME" > /dev/null 2>&1 || true
# Ask user which indexer to use
echo ""
echo "Choose indexing method:"
echo "1) Full indexer (with browser crawling) - may fail on Apple Silicon Macs"
echo "2) Lite indexer (markdown only) - works everywhere"
echo ""
read -p "Enter choice (1 or 2, default: 2): " choice
case "$choice" in
1)
print_status "Running full indexer to recreate index..."
run_indexer
;;
2|"")
print_status "Running lite indexer to recreate index..."
run_lite_indexer
;;
*)
print_error "Invalid choice. Using lite indexer..."
run_lite_indexer
;;
esac
}
# Function to show logs
show_logs() {
print_header "Service Logs"
if [ -z "$1" ]; then
print_status "Showing logs for all services..."
${DOCKER_COMPOSE} logs -f
else
print_status "Showing logs for service: $1"
${DOCKER_COMPOSE} logs -f "$1"
fi
}
# Function to show usage
show_usage() {
echo "Usage: $0 {start|start-auto|stop|index|index-lite|status|reset|logs|help}"
echo ""
echo "Commands:"
echo " start - Start Elasticsearch, Search Backend, and Kibana services"
echo " start-auto - Start services with automatic periodic indexing"
echo " stop - Stop all services"
echo " index - Run the full search indexer (includes browser crawling)"
echo " index-lite - Run lite indexer (markdown only, no browser dependencies)"
echo " status - Check the status of all services"
echo " reset - Reset the search index and reindex"
echo " logs - Show logs for all services"
echo " help - Show this help message"
echo ""
echo "Examples:"
echo " $0 start # Start Elasticsearch, Search Backend, and Kibana"
echo " $0 start-auto # Start with auto-indexing every hour"
echo " $0 index # Index with browser crawling (may fail on Apple Silicon)"
echo " $0 index-lite # Index markdown only (works everywhere)"
echo " $0 status # Check service status"
echo " $0 logs elasticsearch # Show logs for specific service"
echo ""
echo "Docker Compose Integration:"
echo " All services run in the same Docker Compose environment"
echo " - elasticsearch: Search engine (port 9200, internal only)"
echo " - search-backend: Secure API proxy (port 3001, public)"
echo " - kibana: Management interface (port 5601, localhost only)"
echo " - search-indexer: Full indexing with browser crawling"
echo " - search-indexer-lite: Markdown-only indexing"
echo " - auto-indexer: Periodic indexing (with start-auto)"
echo ""
echo "Note: Use 'index-lite' on Apple Silicon Macs to avoid browser issues"
}
# Main script logic
case "$1" in
start)
start_services
;;
start-auto)
start_with_auto_indexing
;;
stop)
stop_services
;;
index)
run_indexer
;;
index-lite)
run_lite_indexer
;;
status)
check_status
;;
reset)
reset_index
;;
logs)
show_logs "$2"
;;
help|--help|-h)
show_usage
;;
*)
print_error "Unknown command: $1"
echo ""
show_usage
exit 1
;;
esac