-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·209 lines (188 loc) · 6.11 KB
/
start.sh
File metadata and controls
executable file
·209 lines (188 loc) · 6.11 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
#!/bin/bash
# Start Research Assistant GraphRAG Application
# This script starts the application services (assumes setup.sh has been run)
echo "🚀 Starting Research Assistant GraphRAG Application..."
# 1. Verify setup has been completed
echo "📋 Verifying setup..."
if [ ! -d "venv" ]; then
echo "❌ Virtual environment not found. Please run ./setup.sh first."
exit 1
fi
if [ ! -d "frontend/node_modules" ]; then
echo "❌ Frontend dependencies not installed. Please run ./setup.sh first."
exit 1
fi
if ! command -v ollama &> /dev/null; then
echo "❌ Ollama not found. Please run ./setup.sh first."
exit 1
fi
# 2. Function to check if port is available
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null ; then
echo "❌ Port $port is already in use. Please stop the service using that port or choose a different port."
return 1
fi
return 0
}
# 3. Check if required ports are available
echo "🔍 Checking available ports..."
check_port 8000 || exit 1
check_port 3000 || check_port 3001 || exit 1
# 4. Start Docker services
echo "🐳 Starting Docker services..."
if command -v docker-compose &> /dev/null || command -v docker &> /dev/null && docker compose version &> /dev/null; then
if command -v docker-compose &> /dev/null; then
docker-compose up -d
else
docker compose up -d
fi
echo "⏳ Waiting for Neo4j to start..."
sleep 10
else
echo "⚠️ Docker Compose not found. Please ensure Neo4j is running manually."
exit 1
fi
# 5. Verify Neo4j connection
echo "🔗 Verifying Neo4j connection..."
source venv/bin/activate
python3 -c "
from neo4j import GraphDatabase
import os
try:
driver = GraphDatabase.driver(
os.getenv('NEO4J_URI', 'bolt://localhost:7687'),
auth=(os.getenv('NEO4J_USERNAME', 'neo4j'), os.getenv('NEO4J_PASSWORD', 'research2025'))
)
with driver.session() as session:
result = session.run('RETURN 1 as num')
print('✅ Neo4j connection successful')
driver.close()
except Exception as e:
print(f'❌ Neo4j connection failed: {e}')
exit 1
"
# 6. Start Ollama service if not running
echo "🧠 Starting Ollama service..."
if ! nc -z localhost 11434 2>/dev/null; then
echo "🖥️ Starting Ollama service..."
ollama serve &
OLLAMA_PID=$!
sleep 3
fi
# 7. Verify Ollama is accessible
echo "🤖 Verifying Ollama models..."
source venv/bin/activate
python3 -c "
import ollama
try:
response = ollama.generate(model='granite4:micro-h', prompt='Hello', options={'num_predict': 5})
print('✅ Ollama service ready')
except Exception as e:
print(f'❌ Ollama not accessible: {e}')
exit 1
"
# 8. Start FastAPI backend
echo "🐍 Starting FastAPI backend on port 8000..."
source venv/bin/activate
python3 main.py &
BACKEND_PID=$!
# 9. Wait for backend to start
echo "⏳ Waiting for backend to start..."
BACKEND_READY=false
for i in {1..30}; do
echo " Checking backend (attempt $i/30)..."
if curl -s --max-time 5 http://localhost:8000/api/health > /dev/null 2>&1; then
echo "✅ Backend is ready!"
BACKEND_READY=true
break
fi
sleep 2
done
if [ "$BACKEND_READY" = false ]; then
echo "❌ Backend failed to start within expected time"
kill $BACKEND_PID 2>/dev/null || true
kill $OLLAMA_PID 2>/dev/null || true
exit 1
fi
# 10. Start Next.js frontend
echo "⚛️ Starting Next.js frontend..."
cd frontend
if [ -n "$OLLAMA_PID" ]; then
# If we started Ollama, keep it running in background
PORT=3000 npm run dev &
FRONTEND_PID=$!
else
PORT=3000 npm run dev &
FRONTEND_PID=$!
fi
cd ..
# 11. Wait for frontend to start
echo "⏳ Waiting for frontend to start..."
FRONTEND_READY=false
for i in {1..20}; do
echo " Checking frontend (attempt $i/20)..."
if curl -s --max-time 5 http://localhost:3000 > /dev/null 2>&1; then
echo "✅ Frontend is ready!"
FRONTEND_READY=true
break
fi
sleep 2
done
if [ "$FRONTEND_READY" = false ]; then
echo "❌ Frontend failed to start within expected time"
kill $BACKEND_PID 2>/dev/null || true
kill $FRONTEND_PID 2>/dev/null || true
kill $OLLAMA_PID 2>/dev/null || true
exit 1
fi
# 12. Display status and access information
echo ""
echo "🎉 Research Assistant GraphRAG Application is running!"
echo ""
echo "🌐 Frontend: http://localhost:3000"
echo "🔧 Backend API: http://localhost:8000"
echo "📚 API Documentation: http://localhost:8000/docs"
echo "📊 Neo4j Browser: http://localhost:7474"
echo ""
echo "📊 Database Status:"
source venv/bin/activate
python3 -c "
try:
from scripts.eps_retriever import EPSRetriever
retriever = EPSRetriever()
result = retriever.driver.session().run('MATCH (d:EPSDocument) RETURN count(d) as count').single()
count = result['count'] if result else 0
print(f' • EPS documents: {count}')
result = retriever.driver.session().run('MATCH (t:Topic) RETURN count(t) as count').single()
count = result['count'] if result else 0
print(f' • Topics identified: {count}')
result = retriever.driver.session().run('MATCH (e:Entity) RETURN count(e) as count').single()
count = result['count'] if result else 0
print(f' • Entities extracted: {count}')
result = retriever.driver.session().run('MATCH ()-[r:SIMILAR_TO]->() RETURN count(r) as count').single()
count = result['count'] if result else 0
print(f' • Similarity relationships: {count}')
except Exception as e:
print(f' • Error checking database: {e}')
" 2>/dev/null
echo ""
# 13. Function to cleanup processes on exit
cleanup() {
echo ""
echo "🛑 Stopping services..."
kill $BACKEND_PID 2>/dev/null || true
kill $FRONTEND_PID 2>/dev/null || true
kill $OLLAMA_PID 2>/dev/null || true
echo "✅ Services stopped. Goodbye!"
exit 0
}
# 14. Set trap to cleanup on script termination
trap cleanup INT TERM
# 15. Wait for processes
echo "🛑 Press Ctrl+C to stop all services"
echo ""
echo "💡 Ready to query your research assistant!"
echo " Try asking questions in the web interface or via API calls."
echo ""
wait $BACKEND_PID $FRONTEND_PID