-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·64 lines (55 loc) · 1.59 KB
/
Copy pathstart.sh
File metadata and controls
executable file
·64 lines (55 loc) · 1.59 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
#!/bin/bash
# Start study-plan: Python backend + Next.js frontend.
# Usage: ./start.sh [backend-port] [web-port]
BACKEND_PORT=${1:-4000}
WEB_PORT=${2:-3000}
DIR="$(cd "$(dirname "$0")" && pwd)"
cleanup() {
echo ""
echo "[start] Shutting down..."
kill $BACKEND_PID $WEB_PID 2>/dev/null
wait $BACKEND_PID $WEB_PID 2>/dev/null
echo "[start] Done."
exit 0
}
trap cleanup INT TERM
port_in_use() {
ss -tln 2>/dev/null | grep -q ":$1 " || ss -tln6 2>/dev/null | grep -q ":$1 "
}
for port in $BACKEND_PORT $WEB_PORT; do
if port_in_use $port; then
echo "[start] ERROR: port $port is already in use. Stop the other process first:"
echo " ss -tlnp | grep :$port"
exit 1
fi
done
echo "[start] Starting Python backend on port $BACKEND_PORT..."
cd "$DIR/backend"
uv run uvicorn app.main:app --host 0.0.0.0 --port $BACKEND_PORT &
BACKEND_PID=$!
echo "[start] Waiting for backend..."
for i in $(seq 1 30); do
if nc -z localhost $BACKEND_PORT 2>/dev/null || ss -tln 2>/dev/null | grep -q ":$BACKEND_PORT "; then
echo "[start] Backend ready."
break
fi
sleep 1
done
echo "[start] Starting frontend on port $WEB_PORT..."
cd "$DIR/frontend"
if [ ! -d node_modules ]; then
echo "[start] Installing frontend deps..."
npm install
fi
PORT=$WEB_PORT npm run dev &
WEB_PID=$!
echo ""
echo "============================================"
echo " study-plan running"
echo " Web UI: http://localhost:$WEB_PORT"
echo " API: http://localhost:$BACKEND_PORT/api"
echo " WS: ws://localhost:$BACKEND_PORT/ws"
echo " Ctrl+C to stop"
echo "============================================"
echo ""
wait