-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_fullstack.sh
More file actions
executable file
·79 lines (67 loc) · 1.79 KB
/
run_fullstack.sh
File metadata and controls
executable file
·79 lines (67 loc) · 1.79 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
#!/usr/bin/env bash
# Run both StudyBuddy backend and frontend concurrently with logging.
# Works on Linux and macOS.
set -euo pipefail
# ---------- Defaults (override via flags) ----------
HOST="0.0.0.0"
PORT="8000"
# ---------- Resolve paths ----------
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
BACKEND_SCRIPT="$SCRIPT_DIR/run_backend.sh"
FRONTEND_SCRIPT="$SCRIPT_DIR/run_frontend.sh"
LOG_DIR="$SCRIPT_DIR/logs"
mkdir -p "$LOG_DIR"
timestamp="$(date +%Y%m%d-%H%M%S)"
BACKEND_LOG="$LOG_DIR/backend-$timestamp.log"
FRONTEND_LOG="$LOG_DIR/frontend-$timestamp.log"
# ---------- Checks ----------
ensure_exec() {
local f="$1"
if [ ! -f "$f" ]; then
echo "Error: expected script not found: $f" >&2
exit 1
fi
if [ ! -x "$f" ]; then
chmod +x "$f" || {
echo "Error: cannot make executable: $f" >&2
exit 1
}
fi
}
ensure_exec "$BACKEND_SCRIPT"
ensure_exec "$FRONTEND_SCRIPT"
# ---------- Start services ----------
echo "Logs:"
echo " Backend : $BACKEND_LOG"
echo " Frontend: $FRONTEND_LOG"
echo
# Start backend
(
cd "$SCRIPT_DIR"
"$BACKEND_SCRIPT" --host "$HOST" --port "$PORT"
) >> "$BACKEND_LOG" 2>&1 &
BACKEND_PID=$!
# Start frontend
(
cd "$SCRIPT_DIR"
"$FRONTEND_SCRIPT"
) >> "$FRONTEND_LOG" 2>&1 &
FRONTEND_PID=$!
echo "StudyBuddy ready. Access the frontend at http://localhost:3000"
echo "Press Ctrl+C to stop."
# ---------- Cleanup on exit ----------
terminate() {
echo
echo "Shutting down…"
for pid in "$BACKEND_PID" "$FRONTEND_PID"; do
if kill -0 "$pid" >/dev/null 2>&1; then
kill "$pid" >/dev/null 2>&1 || true
fi
done
wait || true
echo "All services stopped."
}
trap terminate INT TERM EXIT
# ---------- Wait for both to finish ----------
# If either exits, wait will return when the remaining one exits or on Ctrl+C
wait