-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_dev.sh
More file actions
174 lines (148 loc) Β· 4.64 KB
/
start_dev.sh
File metadata and controls
174 lines (148 loc) Β· 4.64 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
#!/bin/bash
# Healthcare Data Platform - Development Startup Script
echo "π₯ Starting Healthcare Data Platform"
echo "================================================"
# Function to check Redis connectivity with multiple methods
check_redis() {
echo "π Checking Redis connectivity..."
# Method 1: Try redis-cli if available
if command -v redis-cli >/dev/null 2>&1; then
echo " Trying redis-cli ping..."
if redis-cli -h localhost -p 6379 ping > /dev/null 2>&1; then
echo "β
Redis is running (verified with redis-cli)"
return 0
fi
else
echo " redis-cli not found in PATH (Docker installation?)"
fi
# Method 2: Check if port 6379 is open using netcat
if command -v nc >/dev/null 2>&1; then
echo " Trying netcat connection test..."
if echo "PING" | nc -w 1 localhost 6379 | grep -q "PONG" 2>/dev/null; then
echo "β
Redis is running (verified with netcat)"
return 0
fi
fi
# Method 3: Check if port 6379 is listening using telnet
if command -v telnet >/dev/null 2>&1; then
echo " Trying telnet connection test..."
if timeout 2 bash -c "</dev/tcp/localhost/6379" 2>/dev/null; then
echo "β
Redis port 6379 is open (connection test passed)"
return 0
fi
fi
# Method 4: Python-based check as last resort
if command -v python3 >/dev/null 2>&1; then
echo " Trying Python socket connection..."
if python3 -c "
import socket
import sys
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(2)
result = sock.connect_ex(('localhost', 6379))
sock.close()
if result == 0:
print('β
Redis port 6379 is accessible')
sys.exit(0)
else:
sys.exit(1)
except:
sys.exit(1)
" 2>/dev/null; then
return 0
fi
fi
# All methods failed
echo "β Redis is not running or not accessible on localhost:6379"
echo ""
echo "Please start Redis using one of these methods:"
echo " Native install:"
echo " macOS: brew services start redis"
echo " Linux: sudo systemctl start redis"
echo " Docker:"
echo " docker run -d --name redis -p 6379:6379 redis:alpine"
echo " Docker Compose:"
echo " Add to docker-compose.yml and run: docker-compose up -d redis"
echo ""
echo "To verify Redis is running:"
echo " With redis-cli: redis-cli ping"
echo " With Docker: docker exec redis redis-cli ping"
echo " Check port: nc -zv localhost 6379"
return 1
}
# Check Redis connectivity
if ! check_redis; then
exit 1
fi
# Function to check if port is available
check_port() {
if lsof -Pi :$1 -sTCP:LISTEN -t >/dev/null ; then
echo "β Port $1 is already in use"
return 1
else
echo "β
Port $1 is available"
return 0
fi
}
# Check ports
check_port 8000 || exit 1
check_port 3000 || exit 1
# Setup backend
echo ""
echo "π Setting up Python backend..."
cd backend
# Check if virtual environment exists
if [ ! -d "venv" ]; then
echo "Creating virtual environment..."
python3 -m venv venv
fi
# Activate virtual environment
source venv/bin/activate
# Install dependencies
echo "Installing Python dependencies..."
pip install -r requirements.txt
# Start FastAPI server in background
echo "Starting FastAPI server..."
uvicorn main:app --reload --port 8000 &
BACKEND_PID=$!
# Start arq worker with hot reload in background
echo "Starting background worker with hot reload..."
watchmedo auto-restart --recursive -- arq worker.WorkerSettings &
WORKER_PID=$!
cd ..
# Setup frontend
echo ""
echo "βοΈ Setting up React frontend..."
cd frontend
# Install dependencies if node_modules doesn't exist
if [ ! -d "node_modules" ]; then
echo "Installing Node.js dependencies..."
npm install
fi
# Start React development server in background
echo "Starting React development server..."
npm start &
FRONTEND_PID=$!
cd ..
echo ""
echo "π All services started successfully!"
echo "================================================"
echo "π± Frontend: http://localhost:3000"
echo "π§ Backend API: http://localhost:8000"
echo "π API Docs: http://localhost:8000/docs"
echo "πΎ Form data will be saved to: backend/health_form_data.json"
echo ""
echo "Press Ctrl+C to stop all services"
# Function to cleanup processes
cleanup() {
echo ""
echo "π Stopping all services..."
kill $BACKEND_PID $WORKER_PID $FRONTEND_PID 2>/dev/null
echo "π Goodbye!"
exit 0
}
# Set trap to cleanup on exit
trap cleanup SIGINT SIGTERM
# Wait for all background processes
wait