-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartup.sh
82 lines (68 loc) · 1.66 KB
/
startup.sh
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
#!/bin/bash
set -euo pipefail
TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S")
log_info() {
echo "$TIMESTAMP - INFO: $1"
}
log_error() {
echo "$TIMESTAMP - ERROR: $1" >&2
}
cleanup() {
if [ -f "frontend.pid" ]; then
kill $(cat "frontend.pid")
rm "frontend.pid"
log_info "Frontend process killed and PID file removed."
fi
if [ -f "backend.pid" ]; then
kill $(cat "backend.pid")
rm "backend.pid"
log_info "Backend process killed and PID file removed."
fi
}
trap cleanup EXIT ERR INT TERM
if [ -f ".env" ]; then
source .env
log_info ".env file loaded."
else
log_error ".env file not found."
exit 1
fi
if [ -z "${VITE_PORT}" ] || ! [[ "${VITE_PORT}" =~ ^[0-9]+$ ]]; then
log_error "VITE_PORT is not set or is invalid in .env."
exit 1
fi
if [ -z "${VITE_API_BASE_URL}" ]; then
log_error "VITE_API_BASE_URL is not set in .env."
exit 1
fi
if [ -z "${VITE_JWT_SECRET}" ]; then
log_error "VITE_JWT_SECRET is not set in .env."
exit 1
fi
if [ -z "${VITE_DB_URL}" ]; then
log_error "VITE_DB_URL is not set in .env."
exit 1
fi
log_info "Starting backend service."
cd api
npm install
node server.js &
backend_pid=$!
echo "$backend_pid" > "backend.pid"
log_info "Backend started with PID: $backend_pid"
cd ..
log_info "Starting frontend service."
npm run dev &
frontend_pid=$!
echo "$frontend_pid" > "frontend.pid"
log_info "Frontend started with PID: $frontend_pid"
wait "$backend_pid" "$frontend_pid"
backend_status=$?
frontend_status=$?
if [ "$backend_status" -ne 0 ] || [ "$frontend_status" -ne 0 ]; then
log_error "One or more services failed to start."
exit 1
else
log_info "All services started successfully."
exit 0
fi