-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
347 lines (290 loc) · 9.42 KB
/
Copy pathstart.sh
File metadata and controls
347 lines (290 loc) · 9.42 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
339
340
341
342
343
344
345
346
347
#!/bin/bash
# Simple Menu - Unified Startup Script (Linux/macOS)
# Handles all deployment options in one script
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
GRAY='\033[0;37m'
NC='\033[0m' # No Color
MODE="${1:-menu}"
write_header() {
echo -e "${CYAN}============================================================${NC}"
echo -e "${CYAN} $1${NC}"
echo -e "${CYAN}============================================================${NC}"
echo ""
}
write_success() {
echo -e "${GREEN}✓ $1${NC}"
}
write_warning() {
echo -e "${YELLOW}⚠️ $1${NC}"
}
write_error() {
echo -e "${RED}✗ $1${NC}"
}
write_info() {
echo -e "${BLUE}ℹ️ $1${NC}"
}
write_accent() {
echo -e "${MAGENTA}$1${NC}"
}
test_docker() {
if docker info >/dev/null 2>&1; then
write_success "Docker is running"
return 0
else
write_error "Docker is not running or not installed"
write_info "Please start Docker or install it from: https://docs.docker.com/get-docker/"
return 1
fi
}
get_system_info() {
local memory_kb
local memory_gb
local cpu_cores
local os_name
# Get memory in GB
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
memory_kb=$(grep MemTotal /proc/meminfo | awk '{print $2}')
memory_gb=$(echo "scale=1; $memory_kb / 1024 / 1024" | bc)
cpu_cores=$(nproc)
os_name=$(lsb_release -d 2>/dev/null | cut -f2 || echo "Linux")
elif [[ "$OSTYPE" == "darwin"* ]]; then
memory_bytes=$(sysctl -n hw.memsize)
memory_gb=$(echo "scale=1; $memory_bytes / 1024 / 1024 / 1024" | bc)
cpu_cores=$(sysctl -n hw.ncpu)
os_name="macOS $(sw_vers -productVersion)"
else
memory_gb="Unknown"
cpu_cores="Unknown"
os_name="Unknown"
fi
echo "$memory_gb:$cpu_cores:$os_name"
}
show_system_info() {
local sys_info
sys_info=$(get_system_info)
IFS=':' read -r memory cpu_cores os_name <<< "$sys_info"
write_info "System Information:"
echo -e " • OS: $os_name"
echo -e " • Memory: ${memory} GB"
echo -e " • CPU Cores: $cpu_cores"
echo ""
}
show_menu() {
write_header "Simple Menu - Unified Startup"
show_system_info
write_accent "Available Options:"
echo ""
echo -e "${MAGENTA}1.${NC} Basic Setup"
echo -e "${GRAY} └─ Just the Simple Menu application${NC}"
echo -e "${GRAY} └─ Resource usage: ~200MB RAM${NC}"
echo ""
echo -e "${MAGENTA}2.${NC} Prometheus + Grafana Monitoring (Recommended)"
echo -e "${GRAY} └─ System metrics, performance monitoring, dashboards${NC}"
echo -e "${GRAY} └─ Resource usage: ~512MB RAM${NC}"
echo ""
echo -e "${MAGENTA}3.${NC} ELK Stack Monitoring"
echo -e "${GRAY} └─ Log analysis, debugging, full-text search${NC}"
echo -e "${GRAY} └─ Resource usage: ~2GB RAM${NC}"
echo ""
echo -e "${MAGENTA}4.${NC} Stop All Services"
echo -e "${GRAY} └─ Stop and clean up all running containers${NC}"
echo ""
echo -e "${MAGENTA}5.${NC} View Service Status"
echo -e "${GRAY} └─ Check running containers and their status${NC}"
echo ""
echo -e "${MAGENTA}6.${NC} Exit"
echo ""
}
get_user_choice() {
while true; do
read -p "Select an option (1-6): " choice
if [[ "$choice" =~ ^[1-6]$ ]]; then
echo "$choice"
return
fi
write_warning "Please enter a number between 1 and 6"
done
}
start_basic_setup() {
write_header "Starting Basic Simple Menu"
write_info "Starting Simple Menu application..."
docker-compose up -d
if [ $? -eq 0 ]; then
sleep 5
write_success "Simple Menu started successfully!"
echo ""
write_accent "📱 Access Point:"
echo " • Simple Menu: http://localhost:3000"
echo ""
else
write_error "Failed to start Simple Menu"
fi
}
start_prometheus_setup() {
write_header "Starting Simple Menu with Prometheus + Grafana"
local sys_info memory
sys_info=$(get_system_info)
memory=$(echo "$sys_info" | cut -d':' -f1)
if (( $(echo "$memory < 1" | bc -l) )); then
write_warning "Low memory detected (${memory}GB). This might affect performance."
read -p "Continue anyway? (y/N): " continue_choice
if [[ "$continue_choice" != "y" && "$continue_choice" != "Y" ]]; then
return
fi
fi
write_info "Starting Simple Menu application..."
docker-compose up -d
if [ $? -ne 0 ]; then
write_error "Failed to start Simple Menu application"
return
fi
write_info "Waiting for main application to start..."
sleep 10
write_info "Starting Prometheus + Grafana monitoring..."
docker-compose -f docker-compose.monitoring-simple.yml up -d
if [ $? -eq 0 ]; then
write_info "Waiting for monitoring services to be ready..."
sleep 30
write_success "Simple Menu with Prometheus + Grafana started successfully!"
echo ""
write_accent "📊 Access Points:"
echo " • Simple Menu: http://localhost:3000"
echo " • Grafana: http://localhost:3001 (admin/admin123)"
echo " • Prometheus: http://localhost:9090"
echo " • Node Exporter: http://localhost:9100"
echo " • cAdvisor: http://localhost:8080"
echo ""
else
write_error "Failed to start monitoring services"
fi
}
start_elk_setup() {
write_header "Starting Simple Menu with ELK Stack"
local sys_info memory
sys_info=$(get_system_info)
memory=$(echo "$sys_info" | cut -d':' -f1)
if (( $(echo "$memory < 4" | bc -l) )); then
write_warning "ELK Stack requires at least 4GB RAM. You have ${memory}GB"
read -p "Continue anyway? (y/N): " continue_choice
if [[ "$continue_choice" != "y" && "$continue_choice" != "Y" ]]; then
write_info "Consider using Prometheus + Grafana monitoring instead (option 2)"
return
fi
fi
write_info "Starting Simple Menu application..."
docker-compose up -d
if [ $? -ne 0 ]; then
write_error "Failed to start Simple Menu application"
return
fi
write_info "Waiting for main application to start..."
sleep 10
write_info "Starting ELK Stack monitoring (this may take a few minutes)..."
docker-compose -f docker-compose.elk-simple.yml up -d
if [ $? -eq 0 ]; then
write_info "Waiting for ELK services to be ready (this can take 2-3 minutes)..."
sleep 90
write_success "Simple Menu with ELK Stack started successfully!"
echo ""
write_accent "📊 Access Points:"
echo " • Simple Menu: http://localhost:3000"
echo " • Kibana: http://localhost:5601"
echo " • Elasticsearch: http://localhost:9200"
echo ""
write_warning "Note: ELK Stack uses significant resources. Monitor system performance."
else
write_error "Failed to start ELK services"
fi
}
stop_all_services() {
write_header "Stopping All Services"
write_info "Stopping monitoring services..."
docker-compose -f docker-compose.monitoring-simple.yml down 2>/dev/null || true
docker-compose -f docker-compose.elk-simple.yml down 2>/dev/null || true
docker-compose -f docker-compose.monitoring.yml down 2>/dev/null || true
docker-compose -f docker-compose.elk.yml down 2>/dev/null || true
write_info "Stopping Simple Menu application..."
docker-compose down
write_info "Cleaning up unused containers and networks..."
docker system prune -f >/dev/null 2>&1 || true
write_success "All services stopped successfully!"
}
show_service_status() {
write_header "Service Status"
write_info "Running containers:"
local containers
containers=$(docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" 2>/dev/null)
if [ -n "$containers" ]; then
echo "$containers"
else
write_warning "No containers are currently running"
fi
echo ""
write_info "Docker system information:"
docker system df 2>/dev/null | grep -E "^(TYPE|Images|Containers|Local Volumes)" || true
}
wait_for_keypress() {
echo ""
echo -e "${GRAY}Press any key to continue...${NC}"
read -n 1 -s
echo ""
}
# Main execution
if ! test_docker; then
exit 1
fi
# Handle command line parameters
case "$MODE" in
"basic")
start_basic_setup
exit 0
;;
"prometheus")
start_prometheus_setup
exit 0
;;
"elk")
start_elk_setup
exit 0
;;
"menu")
# Continue to interactive menu
;;
esac
# Interactive menu
while true; do
show_menu
choice=$(get_user_choice)
case $choice in
1)
start_basic_setup
wait_for_keypress
;;
2)
start_prometheus_setup
wait_for_keypress
;;
3)
start_elk_setup
wait_for_keypress
;;
4)
stop_all_services
wait_for_keypress
;;
5)
show_service_status
wait_for_keypress
;;
6)
echo -e "${GREEN}Goodbye! 👋${NC}"
exit 0
;;
esac
done