-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
191 lines (162 loc) Β· 4.69 KB
/
Copy pathstart.sh
File metadata and controls
191 lines (162 loc) Β· 4.69 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
#!/bin/bash
# CoreAI Startup Script
# This script starts all CoreAI services
echo "π Starting CoreAI Multi-Agent System..."
echo "========================================="
# Check if running on Windows (Git Bash or WSL)
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
PYTHON_CMD="python"
VENV_ACTIVATE="venv/Scripts/activate"
else
PYTHON_CMD="python3"
VENV_ACTIVATE="venv/bin/activate"
fi
# Function to check if a port is in use
check_port() {
if command -v lsof &> /dev/null; then
lsof -ti:$1 &> /dev/null
elif command -v netstat &> /dev/null; then
netstat -ano | grep ":$1" &> /dev/null
else
return 1
fi
}
# Function to kill process on port
kill_port() {
echo "β οΈ Port $1 is in use, attempting to free it..."
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "win32" ]]; then
# Windows
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :$1') do taskkill /F /PID %%a 2>nul
else
# Unix-like
lsof -ti:$1 | xargs kill -9 2>/dev/null
fi
}
# Check and clean ports
echo ""
echo "π Checking ports..."
if check_port 3000; then
kill_port 3000
fi
if check_port 3001; then
kill_port 3001
fi
if check_port 5001; then
kill_port 5001
fi
echo "β
Ports are ready"
echo ""
# Start Python backend
echo "1οΈβ£ Starting Python Agent Server (Port 5001)..."
cd backend/agentic
# Check if virtual environment exists
if [ ! -d "venv" ]; then
echo "β οΈ Virtual environment not found. Creating..."
$PYTHON_CMD -m venv venv
source $VENV_ACTIVATE
pip install -r requirements.txt
else
source $VENV_ACTIVATE
fi
# Check if .env exists
if [ ! -f ".env" ]; then
echo "β οΈ .env file not found. Creating from .env.example..."
cp .env.example .env
echo "β οΈ Please edit backend/agentic/.env and add your API keys!"
echo "Press Enter to continue anyway or Ctrl+C to cancel..."
read
fi
# Start Python server in background
$PYTHON_CMD main.py > ../../logs/python.log 2>&1 &
PYTHON_PID=$!
echo "β
Python server started (PID: $PYTHON_PID)"
cd ../..
# Wait for Python server to be ready
echo "β³ Waiting for Python server..."
sleep 3
# Start Node.js proxy
echo ""
echo "2οΈβ£ Starting Node.js Proxy Server (Port 3001)..."
cd backend
# Check if node_modules exists
if [ ! -d "node_modules" ]; then
echo "β οΈ node_modules not found. Installing..."
npm install
fi
# Start Node.js server in background
node index.js > ../logs/nodejs.log 2>&1 &
NODEJS_PID=$!
echo "β
Node.js proxy started (PID: $NODEJS_PID)"
cd ..
# Wait for Node.js server to be ready
echo "β³ Waiting for Node.js proxy..."
sleep 2
# Start Frontend
echo ""
echo "3οΈβ£ Starting Next.js Frontend (Port 3000)..."
cd frontend
# Check if node_modules exists
if [ ! -d "node_modules" ]; then
echo "β οΈ node_modules not found. Installing..."
npm install
fi
# Start frontend in background
npm run dev > ../logs/frontend.log 2>&1 &
FRONTEND_PID=$!
echo "β
Frontend started (PID: $FRONTEND_PID)"
cd ..
# Create logs directory if it doesn't exist
mkdir -p logs
# Summary
echo ""
echo "========================================="
echo "β¨ CoreAI is starting up!"
echo "========================================="
echo ""
echo "π‘ Services:"
echo " β’ Python Agent Server: http://localhost:5001"
echo " β’ Node.js Proxy: http://localhost:3001"
echo " β’ Frontend: http://localhost:3000"
echo ""
echo "π Process IDs:"
echo " β’ Python: $PYTHON_PID"
echo " β’ Node.js: $NODEJS_PID"
echo " β’ Frontend: $FRONTEND_PID"
echo ""
echo "π Logs:"
echo " β’ View logs in the ./logs/ directory"
echo " β’ Python: logs/python.log"
echo " β’ Node.js: logs/nodejs.log"
echo " β’ Frontend: logs/frontend.log"
echo ""
echo "β³ Waiting for services to be fully ready..."
sleep 5
# Health check
echo ""
echo "π₯ Health Check:"
if curl -s http://localhost:5001/health > /dev/null 2>&1; then
echo " β
Python server is healthy"
else
echo " β οΈ Python server not responding (check logs/python.log)"
fi
if curl -s http://localhost:3001/api/health > /dev/null 2>&1; then
echo " β
Node.js proxy is healthy"
else
echo " β οΈ Node.js proxy not responding (check logs/nodejs.log)"
fi
echo ""
echo "========================================="
echo "π CoreAI is ready!"
echo "========================================="
echo ""
echo "π Open your browser to: http://localhost:3000"
echo ""
echo "To stop all services, run: ./stop.sh"
echo "Or press Ctrl+C to keep services running in background"
echo ""
# Save PIDs to file for stop script
echo "$PYTHON_PID" > .pids
echo "$NODEJS_PID" >> .pids
echo "$FRONTEND_PID" >> .pids
# Keep script running
wait