-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·125 lines (108 loc) · 5.12 KB
/
Copy pathdev.sh
File metadata and controls
executable file
·125 lines (108 loc) · 5.12 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
# dev.sh — Start ParleyLab dev servers on Linux
#
# Usage: ./dev.sh
#
# This script:
# 1. Kills anything already on ports 8000 / 3000
# 2. Starts the FastAPI backend in the CURRENT terminal
# 3. Opens a SEPARATE terminal for live LLM usage logs
# 4. Opens a SEPARATE terminal for the Next.js frontend
#
# Requirements: gnome-terminal (default on Ubuntu/GNOME), or xterm as fallback.
set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKEND_DIR="$PROJECT_ROOT/backend"
FRONTEND_DIR="$PROJECT_ROOT/frontend"
VENV_DIR="$PROJECT_ROOT/.venv"
# ── Colours ────────────────────────────────────────────────────────────────────
RED='\033[0;31m'
GREEN='\033[0;32m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# ── Kill processes on a port ───────────────────────────────────────────────────
kill_port() {
local port=$1
local pids
pids=$(lsof -ti :"$port" 2>/dev/null || true)
if [[ -n "$pids" ]]; then
echo -e "${YELLOW}Killing processes on port $port...${NC}"
echo "$pids" | xargs kill -9 2>/dev/null || true
sleep 0.5
fi
}
# ── Detect terminal emulator ──────────────────────────────────────────────────
detect_terminal() {
if command -v gnome-terminal &>/dev/null; then
echo "gnome-terminal"
elif command -v xterm &>/dev/null; then
echo "xterm"
elif command -v konsole &>/dev/null; then
echo "konsole"
elif command -v xfce4-terminal &>/dev/null; then
echo "xfce4-terminal"
else
echo "none"
fi
}
TERM_APP=$(detect_terminal)
open_in_terminal() {
local title="$1"
local cmd="$2"
case "$TERM_APP" in
gnome-terminal)
gnome-terminal --title="$title" -- bash -c "$cmd; exec bash" &
;;
konsole)
konsole --new-tab -e bash -c "$cmd; exec bash" &
;;
xfce4-terminal)
xfce4-terminal --title="$title" -e "bash -c '$cmd; exec bash'" &
;;
xterm)
xterm -title "$title" -e "bash -c '$cmd; exec bash'" &
;;
*)
echo -e "${RED}No supported terminal emulator found. Running in background.${NC}"
bash -c "$cmd" &
;;
esac
}
# ── Main ──────────────────────────────────────────────────────────────────────
echo -e "${CYAN}╔═══════════════════════════════════════════════╗${NC}"
echo -e "${CYAN}║ ParleyLab Dev Launcher ║${NC}"
echo -e "${CYAN}╚═══════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}Stopping any existing servers...${NC}"
kill_port 8000
kill_port 3000
kill_port 3001
kill_port 3002
sleep 1
# ── Activate venv if present ─────────────────────────────────────────────────
ACTIVATE=""
if [[ -f "$VENV_DIR/bin/activate" ]]; then
ACTIVATE="source $VENV_DIR/bin/activate &&"
fi
# ── Start LLM monitor terminal ──────────────────────────────────────────────
echo -e "${GREEN}Opening LLM monitor terminal...${NC}"
LLM_MONITOR_CMD="$ACTIVATE echo -e '${CYAN}═══ ParleyLab LLM Monitor ═══${NC}' && echo 'Waiting for backend to start...' && sleep 3 && echo 'Polling /api/status/llm every 3s...' && while true; do echo '──────────────────────────────────' && date '+%H:%M:%S' && curl -s http://localhost:8000/api/status/llm 2>/dev/null | python3 -m json.tool 2>/dev/null || echo '⏳ Backend not ready yet...'; sleep 3; done"
open_in_terminal "ParleyLab — LLM Monitor" "$LLM_MONITOR_CMD"
# ── Start Next.js frontend in separate terminal ─────────────────────────────
echo -e "${GREEN}Starting Next.js frontend (port 3000) in new terminal...${NC}"
FRONTEND_CMD="cd $FRONTEND_DIR && npm run dev"
open_in_terminal "ParleyLab — Frontend (3000)" "$FRONTEND_CMD"
sleep 1
# ── Start FastAPI backend in THIS terminal ───────────────────────────────────
echo -e "${GREEN}Starting FastAPI backend (port 8000) in this terminal...${NC}"
echo ""
echo -e "${CYAN}Backend: http://localhost:8000/docs${NC}"
echo -e "${CYAN}Frontend: http://localhost:3000${NC}"
echo -e "${CYAN}Health: http://localhost:8000/healthz${NC}"
echo ""
cd "$BACKEND_DIR"
if [[ -f "$VENV_DIR/bin/activate" ]]; then
source "$VENV_DIR/bin/activate"
fi
exec python -m uvicorn main:app --port 8000 --reload