-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·238 lines (214 loc) · 8.17 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·238 lines (214 loc) · 8.17 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
#!/bin/bash
set -e
# ============================================================
# NATURA-EVIDENCE — Single-Command Launcher
# Starts: Backend (FastAPI) + Celery Worker + Frontend (React)
# Kills stale processes on ports 8000, 5173, and old Celery workers
# ============================================================
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
BACKEND_DIR="$PROJECT_DIR/natura-evidence-api"
FRONTEND_DIR="$PROJECT_DIR/natura-evidence-ui"
PIDS=()
# ---- Colors ----
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
CYAN='\033[0;36m'
NC='\033[0m'
cleanup() {
echo ""
echo -e "${YELLOW}Shutting down NATURA-EVIDENCE...${NC}"
for pid in "${PIDS[@]}"; do
kill "$pid" 2>/dev/null || true
done
# Kill anything remaining on our ports
for port in 8000 5173; do
fuser -k "$port/tcp" 2>/dev/null || true
done
# Kill all celery workers for this project
pkill -f "app.tasks.celery_app" 2>/dev/null || true
wait 2>/dev/null
echo -e "${GREEN}All services stopped. Ports 8000 and 5173 freed.${NC}"
}
trap cleanup EXIT INT TERM
echo -e "${CYAN}"
echo "============================================"
echo " NATURA-EVIDENCE Platform Launcher"
echo "============================================"
echo -e "${NC}"
# ---- Step 0: Kill ALL stale processes on our ports ----
echo -e "${YELLOW}[0/7]${NC} Cleaning up stale processes..."
fuser -k 8000/tcp 2>/dev/null || true
fuser -k 5173/tcp 2>/dev/null || true
pkill -f "app.tasks.celery_app" 2>/dev/null || true
sleep 1
echo -e " ${GREEN}✓${NC} Ports 8000, 5173 cleared. Old Celery workers killed."
# ---- Reset stuck pipeline states in Redis ----
echo -e " ${YELLOW}⏳${NC} Resetting stuck pipeline states in Redis..."
cd "$BACKEND_DIR"
source .venv/bin/activate 2>/dev/null
python3 -c "
import redis, os
url = os.environ.get('REDIS_URL', 'redis://localhost:6380/0')
r = redis.from_url(url, decode_responses=True)
# Find all pipeline hashes and reset stuck states
for key in r.keys('pipeline:*:steps'):
pid = key.split(':')[1]
steps = r.hgetall(key)
stuck = [s for s, st in steps.items() if st in ('running', 'queued')]
if stuck:
r.delete(key)
r.delete(f'pipeline:{pid}')
r.delete(f'pipeline:{pid}:logs')
r.delete(f'pipeline:{pid}:stage_runtimes')
r.delete(f'pipeline:{pid}:warnings')
import shutil
import glob
for path in glob.glob(f'data/*/{pid}'):
shutil.rmtree(path, ignore_errors=True)
print(f' Erased stuck pipeline {pid[:8]} completely...')
# Also clear any orphaned task results
for key in r.keys('celery-task-meta-*'):
r.delete(key)
print(' Done.')
" 2>/dev/null || echo -e " ${YELLOW}⚠${NC} Could not reset Redis (will happen on first API call)"
# ---- Start Docker Infrastructure ----
echo -e "${YELLOW}[1/7]${NC} Starting Docker infrastructure (Postgres + Redis)..."
if ! command -v docker >/dev/null 2>&1; then
echo -e " ${RED}✗${NC} Docker not found. Database and cache will not be available."
else
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^natura_evidence_db$'; then
echo -e " ${GREEN}✓${NC} PostgreSQL already running on port 5433"
else
docker rm natura_evidence_db 2>/dev/null || true
docker run -d --name natura_evidence_db \
-e POSTGRES_USER=natura \
-e POSTGRES_PASSWORD=natura_password \
-e POSTGRES_DB=natura_evidence \
-p 5433:5432 \
postgres:15-alpine > /dev/null 2>&1
echo -e " ${GREEN}✓${NC} PostgreSQL started on port 5433"
fi
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q '^natura_evidence_redis$'; then
echo -e " ${GREEN}✓${NC} Redis already running on port 6380"
else
docker rm natura_evidence_redis 2>/dev/null || true
docker run -d --name natura_evidence_redis \
-p 6380:6379 \
redis:7-alpine redis-server --save 60 1 > /dev/null 2>&1
echo -e " ${GREEN}✓${NC} Redis started on port 6380"
fi
fi
echo -e " ${YELLOW}⏳${NC} Waiting for containers to initialize..."
sleep 3
# ---- Check Redis ----
echo -e "${YELLOW}[2/7]${NC} Checking Redis..."
if redis-cli -p 6380 ping > /dev/null 2>&1; then
echo -e " ${GREEN}✓${NC} Redis is running on port 6380"
else
echo -e " ${RED}✗${NC} Redis not responding. Check docker logs."
exit 1
fi
# ---- Check Python venv ----
echo -e "${YELLOW}[3/7]${NC} Checking Python environment..."
if [ ! -d "$BACKEND_DIR/.venv" ]; then
echo -e " ${YELLOW}⚠${NC} Creating Python virtual environment..."
cd "$BACKEND_DIR"
python3 -m venv .venv
source .venv/bin/activate
echo -e " ${YELLOW}⚠${NC} Installing dependencies..."
pip install -r requirements.txt > /dev/null 2>&1
echo -e " ${GREEN}✓${NC} Dependencies installed"
else
source "$BACKEND_DIR/.venv/bin/activate"
echo -e " ${GREEN}✓${NC} Python venv ready"
fi
# ---- Check AutoDock Vina ----
echo -e "${YELLOW}[4/7]${NC} Checking AutoDock Vina..."
if python -c "from vina import Vina" 2>/dev/null; then
echo -e " ${GREEN}✓${NC} AutoDock Vina available (full docking)"
else
echo -e " ${YELLOW}⚠${NC} AutoDock Vina not installed — using RDKit conformer energy fallback"
fi
# ---- Check Node modules ----
echo -e "${YELLOW}[5/7]${NC} Checking Node.js environment..."
if [ ! -d "$FRONTEND_DIR/node_modules" ]; then
echo -e " ${YELLOW}⚠${NC} Installing frontend dependencies..."
cd "$FRONTEND_DIR"
npm install > /dev/null 2>&1
echo -e " ${GREEN}✓${NC} Frontend dependencies installed"
else
echo -e " ${GREEN}✓${NC} Node modules ready"
fi
# ---- Start Backend ----
echo -e "${YELLOW}[6/7]${NC} Starting Backend API (port 8000)..."
cd "$BACKEND_DIR"
source .venv/bin/activate
uvicorn app.main:app --host 0.0.0.0 --port 8000 > /tmp/natura-backend.log 2>&1 &
BACKEND_PID=$!
PIDS+=($BACKEND_PID)
sleep 4
if kill -0 $BACKEND_PID 2>/dev/null; then
echo -e " ${GREEN}✓${NC} Backend running on http://localhost:8000"
else
echo -e " ${RED}✗${NC} Backend failed. Check /tmp/natura-backend.log"
tail -10 /tmp/natura-backend.log
exit 1
fi
# ---- Start Celery Worker (with ALL queues including 'default') ----
echo -e "${YELLOW}[7/7]${NC} Starting Celery Worker..."
if redis-cli -p 6380 ping > /dev/null 2>&1; then
cd "$BACKEND_DIR"
source .venv/bin/activate
# Use ALL queues that task_routes define + default as safety net
# --pool=solo avoids asyncio event loop issues in Celery fork-pool workers
celery -A app.tasks.celery_app worker \
-Q default,compound,target,protein,disease,pathway,network,docking,admet,literature,clinical,ai,dossier \
--pool=solo \
--loglevel=info \
--concurrency=1 \
> /tmp/natura-celery.log 2>&1 &
CELERY_PID=$!
PIDS+=($CELERY_PID)
sleep 3
if kill -0 $CELERY_PID 2>/dev/null; then
echo -e " ${GREEN}✓${NC} Celery worker running (pool=solo, all queues)"
else
echo -e " ${RED}✗${NC} Celery worker failed. Check /tmp/natura-celery.log"
tail -10 /tmp/natura-celery.log
fi
else
echo -e " ${YELLOW}⚠${NC} Skipping Celery (Redis not available)"
fi
# ---- Start Frontend ----
echo ""
echo -e "${CYAN}Starting Frontend (port 5173)...${NC}"
cd "$FRONTEND_DIR"
npm run dev > /tmp/natura-frontend.log 2>&1 &
FRONTEND_PID=$!
PIDS+=($FRONTEND_PID)
sleep 3
if kill -0 $FRONTEND_PID 2>/dev/null; then
echo -e " ${GREEN}✓${NC} Frontend running on http://localhost:5173"
else
echo -e " ${RED}✗${NC} Frontend failed. Check /tmp/natura-frontend.log"
fi
# ---- Summary ----
echo ""
echo -e "${GREEN}============================================"
echo " NATURA-EVIDENCE is running!"
echo -e "============================================${NC}"
echo ""
echo -e " ${CYAN}Frontend:${NC} http://localhost:5173"
echo -e " ${CYAN}API Docs:${NC} http://localhost:8000/docs"
echo -e " ${CYAN}API:${NC} http://localhost:8000"
echo ""
echo -e " ${YELLOW}Logs:${NC}"
echo " Backend: /tmp/natura-backend.log"
echo " Celery: /tmp/natura-celery.log"
echo " Frontend: /tmp/natura-frontend.log"
echo ""
echo -e " Press ${RED}Ctrl+C${NC} to stop all services"
echo ""
# ---- Keep running ----
wait