-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·389 lines (346 loc) · 11.1 KB
/
dev.sh
File metadata and controls
executable file
·389 lines (346 loc) · 11.1 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
#!/usr/bin/env bash
# Manage both frontend and backend dev servers
#
# Usage:
# ./dev.sh - Stop then start both servers
# ./dev.sh start - Start both servers
# ./dev.sh stop - Stop both servers
# ./dev.sh status - Check status of both servers
# ./dev.sh frontend start - Start only frontend
# ./dev.sh frontend stop - Stop only frontend
# ./dev.sh frontend status - Check frontend status
# ./dev.sh backend start - Start only backend
# ./dev.sh backend stop - Stop only backend
# ./dev.sh backend status - Check backend status
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
stop_backend() {
echo "=================================================="
echo "Stopping Backend Server"
echo "=================================================="
echo ""
"$SCRIPT_DIR/backend/scripts/stop-backend.sh"
echo ""
}
stop_frontend() {
echo "=================================================="
echo "Stopping Frontend Server"
echo "=================================================="
echo ""
"$SCRIPT_DIR/frontend/scripts/stop-frontend.sh"
echo ""
}
stop_servers() {
echo "=================================================="
echo "Stopping Development Servers"
echo "=================================================="
echo ""
"$SCRIPT_DIR/backend/scripts/stop-backend.sh"
echo ""
"$SCRIPT_DIR/frontend/scripts/stop-frontend.sh"
echo ""
}
# Helper function to check backend status
# Returns: 0 if running and responding, 1 if running but not responding, 2 if not running
check_backend_status() {
if pgrep -f "go run.*cmd/admin" > /dev/null; then
# Process is running, check if responding
if curl -s -o /dev/null -w "%{http_code}" http://localhost:6180/api/health 2>/dev/null | grep -q "200\|404"; then
return 0 # Running and responding
else
return 1 # Running but not responding
fi
else
return 2 # Not running
fi
}
# Helper function to check frontend status
# Returns: 0 if running and responding, 1 if running but not responding, 2 if not running
check_frontend_status() {
if pgrep -f "node_modules/.bin/vite" > /dev/null; then
# Process is running, check if responding
if curl -s -o /dev/null -w "%{http_code}" http://localhost:5173 2>/dev/null | grep -q "200"; then
return 0 # Running and responding
else
return 1 # Running but not responding
fi
else
return 2 # Not running
fi
}
status_backend() {
echo "=================================================="
echo "Backend Server Status"
echo "=================================================="
echo ""
check_backend_status
local status=$?
case $status in
0)
echo "✓ Backend server is RUNNING"
echo " Process: $(pgrep -f 'go run.*cmd/admin')"
echo " URL: http://localhost:6180"
echo " Status: Responding to requests"
;;
1)
echo "⚠ Backend server is RUNNING"
echo " Process: $(pgrep -f 'go run.*cmd/admin')"
echo " URL: http://localhost:6180"
echo " Warning: Process running but not responding"
;;
2)
echo "✗ Backend server is NOT running"
;;
esac
echo ""
}
status_frontend() {
echo "=================================================="
echo "Frontend Server Status"
echo "=================================================="
echo ""
check_frontend_status
local status=$?
case $status in
0)
echo "✓ Frontend server is RUNNING"
echo " Process: $(pgrep -f 'node_modules/.bin/vite')"
echo " URL: http://localhost:5173"
echo " Status: Responding to requests"
;;
1)
echo "⚠ Frontend server is RUNNING"
echo " Process: $(pgrep -f 'node_modules/.bin/vite')"
echo " URL: http://localhost:5173"
echo " Warning: Process running but not responding"
;;
2)
echo "✗ Frontend server is NOT running"
;;
esac
echo ""
}
status_servers() {
echo "=================================================="
echo "Development Servers Status"
echo "=================================================="
echo ""
# Check backend
check_backend_status
local backend_status=$?
case $backend_status in
0)
echo "✓ Backend: RUNNING (http://localhost:6180)"
echo " Responding to requests"
;;
1)
echo "⚠ Backend: RUNNING (http://localhost:6180)"
echo " Warning: Not responding"
;;
2)
echo "✗ Backend: NOT running"
;;
esac
echo ""
# Check frontend
check_frontend_status
local frontend_status=$?
case $frontend_status in
0)
echo "✓ Frontend: RUNNING (http://localhost:5173)"
echo " Responding to requests"
;;
1)
echo "⚠ Frontend: RUNNING (http://localhost:5173)"
echo " Warning: Not responding"
;;
2)
echo "✗ Frontend: NOT running"
;;
esac
echo ""
echo "=================================================="
}
start_backend() {
echo "=================================================="
echo "Starting Backend Server"
echo "=================================================="
echo ""
# Trap Ctrl+C and cleanup
cleanup() {
echo ""
echo "Shutting down backend server..."
"$SCRIPT_DIR/backend/scripts/stop-backend.sh"
exit 0
}
trap cleanup INT TERM
"$SCRIPT_DIR/backend/scripts/start-backend.sh"
echo ""
echo "=================================================="
echo "Backend Server Running"
echo "=================================================="
echo "Backend: http://localhost:6180"
echo "Admin: http://localhost:5173/admin/login"
echo ""
echo "Press Ctrl+C to stop the server"
echo "View logs: tail -f backend/server.log"
echo "=================================================="
# Keep script running and wait for Ctrl+C
wait
}
start_frontend() {
echo "=================================================="
echo "Starting Frontend Server"
echo "=================================================="
echo ""
# Trap Ctrl+C and cleanup
cleanup() {
echo ""
echo "Shutting down frontend server..."
"$SCRIPT_DIR/frontend/scripts/stop-frontend.sh"
exit 0
}
trap cleanup INT TERM
"$SCRIPT_DIR/frontend/scripts/start-frontend.sh"
echo ""
echo "=================================================="
echo "Frontend Server Running"
echo "=================================================="
echo "Frontend: http://localhost:5173"
echo "Admin: http://localhost:5173/admin/login"
echo ""
echo "Press Ctrl+C to stop the server"
echo "View logs: tail -f frontend/server.log"
echo "=================================================="
# Keep script running and wait for Ctrl+C
wait
}
start_servers() {
echo "=================================================="
echo "Starting Development Servers"
echo "=================================================="
echo ""
# Trap Ctrl+C and cleanup both servers
cleanup() {
echo ""
echo "Shutting down servers..."
"$SCRIPT_DIR/backend/scripts/stop-backend.sh"
"$SCRIPT_DIR/frontend/scripts/stop-frontend.sh"
exit 0
}
trap cleanup INT TERM
# Start backend server
"$SCRIPT_DIR/backend/scripts/start-backend.sh"
echo ""
# Start frontend server
"$SCRIPT_DIR/frontend/scripts/start-frontend.sh"
echo ""
echo "=================================================="
echo "Development Servers Running"
echo "=================================================="
echo "Frontend: http://localhost:5173"
echo "Backend: http://localhost:6180"
echo "Admin: http://localhost:5173/admin/login"
echo ""
echo "Press Ctrl+C to stop both servers"
echo "View logs:"
echo " Frontend: tail -f frontend/server.log"
echo " Backend: tail -f backend/server.log"
echo "=================================================="
# Keep script running and wait for Ctrl+C
wait
}
show_usage() {
echo "Usage:"
echo " ./dev.sh - Stop then start both servers"
echo " ./dev.sh start - Start both servers"
echo " ./dev.sh stop - Stop both servers"
echo " ./dev.sh status - Check status of both servers"
echo " ./dev.sh frontend start - Start only frontend"
echo " ./dev.sh frontend stop - Stop only frontend"
echo " ./dev.sh frontend status - Check frontend status"
echo " ./dev.sh backend start - Start only backend"
echo " ./dev.sh backend stop - Stop only backend"
echo " ./dev.sh backend status - Check backend status"
}
# Parse commands
if [ $# -eq 0 ]; then
# No arguments: restart both
stop_servers
start_servers
elif [ $# -eq 1 ]; then
# One argument: start/stop both
COMMAND="$1"
case "$COMMAND" in
start)
start_servers
;;
stop)
stop_servers
;;
status)
status_servers
;;
*)
echo "Error: Unknown command '$COMMAND'"
echo ""
show_usage
exit 1
;;
esac
elif [ $# -eq 2 ]; then
# Two arguments: service + command
SERVICE="$1"
COMMAND="$2"
case "$SERVICE" in
frontend)
case "$COMMAND" in
start)
start_frontend
;;
stop)
stop_frontend
;;
status)
status_frontend
;;
*)
echo "Error: Unknown command '$COMMAND' for frontend"
echo ""
show_usage
exit 1
;;
esac
;;
backend)
case "$COMMAND" in
start)
start_backend
;;
stop)
stop_backend
;;
status)
status_backend
;;
*)
echo "Error: Unknown command '$COMMAND' for backend"
echo ""
show_usage
exit 1
;;
esac
;;
*)
echo "Error: Unknown service '$SERVICE'"
echo ""
show_usage
exit 1
;;
esac
else
echo "Error: Too many arguments"
echo ""
show_usage
exit 1
fi