-
Notifications
You must be signed in to change notification settings - Fork 87
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·75 lines (60 loc) · 2.13 KB
/
start.sh
File metadata and controls
executable file
·75 lines (60 loc) · 2.13 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
#!/usr/bin/env bash
CLEANED_UP=false
cleanup() {
if [ "$CLEANED_UP" = true ]; then return; fi
CLEANED_UP=true
red "⚠️ Cleaning up services..."
kill "$TAIL_REACT" "$TAIL_EXPRESS" "$TAIL_FASTAPI" 2>/dev/null
kill "$REACT_PID" "$EXPRESS_PID" "$FASTAPI_PID" 2>/dev/null
exit 1
}
trap cleanup INT TERM EXIT
# === Utility for colored messages ===
green() { printf '\033[1;32m%s\033[0m\n' "$1"; }
red() { printf '\033[1;31m%s\033[0m\n' "$1"; }
echo "🧹 Clearing previous logs..."
: > react.log && : > express.log && : > fastapi.log
# === Free ports (5173, 3000, 8000) ===
command -v lsof >/dev/null 2>&1 || {
red "❌ lsof is not installed. Please install it to continue."
exit 1
}
for port in 5173 3000 8000; do
pid=$(lsof -ti :$port 2>/dev/null || pkill -f ":$port")
if [ -n "$pid" ]; then
red "🛑 Port $port in use (PID $pid). Killing..."
kill -9 $pid
else
green "✅ Port $port is free."
fi
done
echo "🔄 Starting all services with live logs..."
# === Start React (Vite) ===
(cd Clients && npm run dev >> ../react.log 2>&1) &
REACT_PID=$!
green "▶️ React (Vite) → http://localhost:5173"
# === Start Express ===
(cd Servers && npm run watch >> ../express.log 2>&1) &
EXPRESS_PID=$!
green "▶️ Express → http://localhost:3000"
# === Start FastAPI ===
(cd BiasAndFairnessServers/src && source .venv/bin/activate && uvicorn app:app --reload --port 8000 >> ../fastapi.log 2>&1) &
FASTAPI_PID=$!
green "▶️ FastAPI → http://localhost:8000"
# === Small delay before showing logs ===
sleep 2
echo ""
green "📺 Showing live logs (press Ctrl+C to stop)..."
echo "─────────────── REACT ───────────────"
tail -n 20 -f react.log &
TAIL_REACT=$!
echo "────────────── EXPRESS ─────────────"
tail -n 20 -f express.log &
TAIL_EXPRESS=$!
echo "────────────── FASTAPI ─────────────"
tail -n 20 -f fastapi.log &
TAIL_FASTAPI=$!
# Wait for any process to exit
wait -n $REACT_PID $EXPRESS_PID $FASTAPI_PID
# If any service exits, stop tails and others
cleanup