-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·264 lines (213 loc) · 6.84 KB
/
dev.sh
File metadata and controls
executable file
·264 lines (213 loc) · 6.84 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#!/bin/bash
# Clausea Development Script
# Runs both frontend and backend simultaneously
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to kill process and its children
kill_process_tree() {
local pid=$1
if [ -z "$pid" ]; then
return
fi
# Try graceful shutdown first
if kill -0 $pid 2>/dev/null; then
# Send TERM signal to the process group (negative PID kills the group)
kill -TERM -$pid 2>/dev/null || kill -TERM $pid 2>/dev/null || true
# Wait a bit for graceful shutdown
sleep 2
# Force kill if still running
if kill -0 $pid 2>/dev/null; then
kill -KILL -$pid 2>/dev/null || kill -KILL $pid 2>/dev/null || true
fi
fi
}
# Function to cleanup background processes
cleanup() {
print_status "Shutting down development servers..."
# Kill backend process tree
if [ ! -z "$BACKEND_PID" ]; then
print_status "Stopping backend server (PID: $BACKEND_PID)..."
kill_process_tree $BACKEND_PID
fi
# Kill frontend process tree
if [ ! -z "$FRONTEND_PID" ]; then
print_status "Stopping frontend server (PID: $FRONTEND_PID)..."
kill_process_tree $FRONTEND_PID
fi
# Fallback: Kill processes by port (in case PIDs weren't captured correctly)
print_status "Cleaning up any remaining processes on ports 8000 and 3000..."
# Kill processes on port 8000 (backend)
if command -v lsof &> /dev/null; then
lsof -ti:8000 | xargs kill -TERM 2>/dev/null || true
sleep 1
lsof -ti:8000 | xargs kill -KILL 2>/dev/null || true
elif command -v fuser &> /dev/null; then
fuser -k 8000/tcp 2>/dev/null || true
fi
# Kill processes on port 3000 (frontend)
if command -v lsof &> /dev/null; then
lsof -ti:3000 | xargs kill -TERM 2>/dev/null || true
sleep 1
lsof -ti:3000 | xargs kill -KILL 2>/dev/null || true
elif command -v fuser &> /dev/null; then
fuser -k 3000/tcp 2>/dev/null || true
fi
# Remove temporary files
rm -f /tmp/clausea_backend.pid /tmp/clausea_frontend.pid
print_success "Development environment cleaned up"
exit 0
}
# Set up signal handlers for graceful shutdown
trap cleanup SIGINT SIGTERM
# Check if required tools are installed
check_dependencies() {
print_status "Checking dependencies..."
# Check for Python and uv
if ! command -v python3 &> /dev/null; then
print_error "Python 3 is required but not installed"
exit 1
fi
if ! command -v uv &> /dev/null; then
print_error "uv is required but not installed. Install from https://docs.astral.sh/uv/getting-started/installation/"
exit 1
fi
# Check for Node.js and bun
if ! command -v node &> /dev/null; then
print_error "Node.js is required but not installed"
exit 1
fi
if ! command -v bun &> /dev/null; then
print_error "bun is required but not installed. Install from https://bun.sh/"
exit 1
fi
print_success "All dependencies are installed"
}
# Install backend dependencies
setup_backend() {
print_status "Setting up backend..."
cd packages/backend
# Install dependencies using uv sync (handles venv creation)
print_status "Installing backend dependencies..."
uv sync
cd ../..
print_success "Backend setup complete"
}
# Install frontend dependencies
setup_frontend() {
print_status "Setting up frontend..."
cd packages/frontend
print_status "Installing frontend dependencies..."
bun install
cd ../..
print_success "Frontend setup complete"
}
# Start backend server
start_backend() {
print_status "Starting backend server..."
cd packages/backend
# Start backend server using uv in a new process group
# Using setsid or starting in subshell to ensure process group creation
(uv run python -m uvicorn main:app --host 0.0.0.0 --port 8000 --reload) &
BACKEND_PID=$!
echo $BACKEND_PID > /tmp/clausea_backend.pid
cd ../..
print_success "Backend server started on http://localhost:8000 (PID: $BACKEND_PID)"
}
# Start frontend server
start_frontend() {
print_status "Starting frontend server..."
cd packages/frontend
# Start Next.js development server in a new process group
(bun run dev) &
FRONTEND_PID=$!
echo $FRONTEND_PID > /tmp/clausea_frontend.pid
cd ../..
print_success "Frontend server started on http://localhost:3000 (PID: $FRONTEND_PID)"
}
# Wait for servers to be ready
wait_for_servers() {
print_status "Waiting for servers to be ready..."
# Wait for backend
print_status "Waiting for backend server..."
for i in {1..30}; do
if curl -s http://localhost:8000/health > /dev/null 2>&1; then
print_success "Backend server is ready!"
break
fi
if [ $i -eq 30 ]; then
print_error "Backend server failed to start within 30 seconds"
cleanup
fi
sleep 1
done
# Wait for frontend
print_status "Waiting for frontend server..."
for i in {1..30}; do
if curl -s http://localhost:3000 > /dev/null 2>&1; then
print_success "Frontend server is ready!"
break
fi
if [ $i -eq 30 ]; then
print_error "Frontend server failed to start within 30 seconds"
cleanup
fi
sleep 1
done
}
# Main execution
main() {
echo "🚀 Starting Clausea Development Environment"
echo "=============================================="
# Check dependencies
check_dependencies
# Setup both applications
setup_backend
setup_frontend
# Start servers
start_backend
start_frontend
# Wait for servers to be ready
wait_for_servers
echo ""
echo "🎉 Development environment is ready!"
echo "=============================================="
echo "Frontend: http://localhost:3000"
echo "Backend: http://localhost:8000"
echo "Health: http://localhost:8000/health"
echo ""
echo "Press Ctrl+C to stop all servers"
echo ""
# Keep script running and monitor processes
while true; do
# Check if processes are still running
if ! kill -0 $BACKEND_PID 2>/dev/null; then
print_error "Backend server has stopped unexpectedly"
cleanup
fi
if ! kill -0 $FRONTEND_PID 2>/dev/null; then
print_error "Frontend server has stopped unexpectedly"
cleanup
fi
sleep 5
done
}
# Run main function
main