-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.command
More file actions
executable file
·103 lines (86 loc) · 2.45 KB
/
start.command
File metadata and controls
executable file
·103 lines (86 loc) · 2.45 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
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_DIR="$SCRIPT_DIR/backend"
FRONTEND_DIR="$SCRIPT_DIR/frontend"
STATE_DIR="$SCRIPT_DIR/.run-state"
if [[ -f "$SCRIPT_DIR/.env" ]]; then
set -a
# shellcheck disable=SC1091
source "$SCRIPT_DIR/.env"
set +a
fi
if [[ -z "${JAVA_HOME:-}" ]] || ! "$JAVA_HOME/bin/java" -version 2>&1 | grep -q "version \"21"; then
for candidate in \
/opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home \
/usr/local/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home \
/Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home; do
if [[ -x "$candidate/bin/java" ]]; then
export JAVA_HOME="$candidate"
export PATH="$JAVA_HOME/bin:$PATH"
break
fi
done
fi
BACKEND_PID_FILE="$STATE_DIR/backend.pid"
FRONTEND_PID_FILE="$STATE_DIR/frontend.pid"
cleanup_pid_file() {
local file="$1"
if [[ ! -f "$file" ]]; then
return
fi
local pid
pid="$(cat "$file" 2>/dev/null || true)"
if [[ -n "$pid" ]] && kill -0 "$pid" 2>/dev/null; then
kill "$pid" 2>/dev/null || true
for _ in {1..20}; do
if ! kill -0 "$pid" 2>/dev/null; then
break
fi
sleep 0.1
done
if kill -0 "$pid" 2>/dev/null; then
kill -9 "$pid" 2>/dev/null || true
fi
fi
rm -f "$file"
}
cleanup() {
if [[ -n "${FRONTEND_PID:-}" ]] && kill -0 "$FRONTEND_PID" 2>/dev/null; then
kill "$FRONTEND_PID" 2>/dev/null || true
fi
if [[ -n "${BACKEND_PID:-}" ]] && kill -0 "$BACKEND_PID" 2>/dev/null; then
kill "$BACKEND_PID" 2>/dev/null || true
fi
rm -f "$BACKEND_PID_FILE" "$FRONTEND_PID_FILE"
}
mkdir -p "$STATE_DIR"
cleanup_pid_file "$BACKEND_PID_FILE"
cleanup_pid_file "$FRONTEND_PID_FILE"
trap cleanup EXIT
trap 'cleanup; exit 130' INT
trap 'cleanup; exit 143' TERM
cd "$BACKEND_DIR"
./mvnw spring-boot:run &
BACKEND_PID=$!
printf '%s\n' "$BACKEND_PID" > "$BACKEND_PID_FILE"
cd "$FRONTEND_DIR"
npm install
FRONTEND_PORT="${FRONTEND_PORT:-4200}"
while lsof -nP -iTCP:"$FRONTEND_PORT" -sTCP:LISTEN >/dev/null 2>&1; do
FRONTEND_PORT=$((FRONTEND_PORT + 1))
done
NG_CLI_ANALYTICS=false CI=true npm start -- --host 0.0.0.0 --port "$FRONTEND_PORT" &
FRONTEND_PID=$!
printf '%s\n' "$FRONTEND_PID" > "$FRONTEND_PID_FILE"
while true; do
if ! kill -0 "$BACKEND_PID" 2>/dev/null; then
wait "$BACKEND_PID" || true
exit 1
fi
if ! kill -0 "$FRONTEND_PID" 2>/dev/null; then
wait "$FRONTEND_PID" || true
exit 1
fi
sleep 1
done