forked from brobertsaz/claude-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_all_services.sh
More file actions
executable file
·266 lines (244 loc) · 8.25 KB
/
start_all_services.sh
File metadata and controls
executable file
·266 lines (244 loc) · 8.25 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
265
266
#!/bin/bash
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Detect OS
if [[ "$OSTYPE" == "darwin"* ]]; then
OS="macos"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
OS="linux"
else
OS="unknown"
fi
echo -e "${BLUE}=================================================="
echo "🚀 Claude OS - Starting All Services"
echo "=================================================${NC}"
echo ""
# Get the project directory
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$PROJECT_DIR"
# Function to check if a port is in use
check_port() {
local port=$1
if nc -z localhost $port 2>/dev/null; then
return 0
else
return 1
fi
}
# Function to wait for a service to be ready
wait_for_port() {
local port=$1
local service=$2
local max_attempts=30
local attempt=0
while ! check_port $port && [ $attempt -lt $max_attempts ]; do
echo -n "."
sleep 1
((attempt++))
done
if check_port $port; then
echo -e " ${GREEN}✓${NC}"
return 0
else
echo -e " ${RED}✗${NC}"
return 1
fi
}
# ===== 1. Check Ollama =====
echo -e "${YELLOW}1. Checking Ollama...${NC}"
if check_port 11434; then
echo -e " ${GREEN}✓ Ollama is running on port 11434${NC}"
else
echo -e " ${YELLOW}⚠ Ollama is not running, attempting to start...${NC}"
if [[ "$OS" == "macos" ]]; then
brew services start ollama > /dev/null 2>&1 || true
elif [[ "$OS" == "linux" ]]; then
# Try direct execution first (no sudo needed), fall back to user systemctl
ollama serve > /dev/null 2>&1 &
else
ollama serve > /dev/null 2>&1 &
fi
echo -n " Waiting for Ollama to start"
if wait_for_port 11434 "Ollama"; then
:
else
echo -e " ${YELLOW}⚠ Could not verify Ollama is running${NC}"
fi
fi
# Verify models are available
echo -n " Checking models"
for model in llama3.1:latest nomic-embed-text:latest; do
if ollama list | grep -q "$model"; then
echo -n "."
else
echo -e "\n ${YELLOW}⚠ Model $model not found, pulling...${NC}"
ollama pull $model > /dev/null 2>&1 || true
echo -n " "
fi
done
echo -e " ${GREEN}✓${NC}"
echo ""
# ===== 2. Setup Python Environment =====
echo -e "${YELLOW}2. Setting up Python environment...${NC}"
if [ ! -d "venv" ]; then
echo " Creating virtual environment..."
python3 -m venv venv
fi
source venv/bin/activate
pip install -q --upgrade pip setuptools wheel 2>/dev/null || true
echo -e " ${GREEN}✓ Python environment ready${NC}"
echo ""
# ===== 3. Ensure data directory exists =====
echo -e "${YELLOW}3. Checking data directory...${NC}"
if [ ! -d "data" ]; then
mkdir -p data
echo -e " ${GREEN}✓ Created data/ directory${NC}"
else
echo -e " ${GREEN}✓ data/ directory exists${NC}"
fi
if [ ! -d "logs" ]; then
mkdir -p logs
echo -e " ${GREEN}✓ Created logs/ directory${NC}"
else
echo -e " ${GREEN}✓ logs/ directory exists${NC}"
fi
echo ""
# ===== 4. Check Redis =====
echo -e "${YELLOW}4. Checking Redis...${NC}"
if ! command -v redis-server &> /dev/null; then
echo -e " ${YELLOW}⚠ Redis is not installed${NC}"
if [[ "$OS" == "macos" ]]; then
echo " Install with: brew install redis"
elif [[ "$OS" == "linux" ]]; then
echo " Install with: sudo apt install redis-server (or dnf/pacman)"
fi
echo " Or run ./setup.sh for full installation"
elif redis-cli ping &> /dev/null; then
echo -e " ${GREEN}✓ Redis is running${NC}"
else
echo -e " ${YELLOW}⚠ Redis is not running, attempting to start...${NC}"
if [[ "$OS" == "macos" ]]; then
brew services start redis > /dev/null 2>&1 || redis-server --daemonize yes > /dev/null 2>&1 || true
else
redis-server --daemonize yes > /dev/null 2>&1 || true
fi
sleep 2
if redis-cli ping &> /dev/null; then
echo -e " ${GREEN}✓ Redis started successfully${NC}"
else
echo -e " ${RED}❌ Could not start Redis${NC}"
echo " Please start Redis manually: redis-server"
fi
fi
echo ""
# ===== 5. Start RQ Workers (Real-Time Learning System) =====
echo -e "${YELLOW}5. Starting RQ Workers (Real-Time Learning)...${NC}"
if check_port 6379; then
nohup "$PROJECT_DIR/venv/bin/python3" -m rq worker claude-os:learning claude-os:prompts claude-os:ingest --with-scheduler > "$PROJECT_DIR/logs/rq_workers.log" 2>&1 &
RQ_PID=$!
echo " RQ Workers PID: $RQ_PID (logging to logs/rq_workers.log)"
echo -e " ${GREEN}✓ RQ workers started${NC}"
else
echo -e " ${YELLOW}⚠ Redis not available, skipping RQ workers${NC}"
fi
echo ""
# ===== 6. Start MCP Server =====
echo -e "${YELLOW}6. Starting MCP Server...${NC}"
if check_port 8051; then
echo -e " ${YELLOW}⚠ Port 8051 already in use, killing existing process...${NC}"
lsof -i :8051 | grep -v COMMAND | awk '{print $2}' | xargs kill -9 2>/dev/null || true
sleep 1
fi
cd "$PROJECT_DIR/mcp_server"
nohup env SQLITE_DB_PATH="$PROJECT_DIR/data/claude-os.db" "$PROJECT_DIR/venv/bin/python3" server.py > "$PROJECT_DIR/logs/mcp_server.log" 2>&1 &
MCP_PID=$!
echo " Server PID: $MCP_PID (logging to logs/mcp_server.log)"
echo -n " Waiting for server to start"
if wait_for_port 8051 "MCP Server"; then
:
else
echo -e " ${YELLOW}⚠ Could not verify server is running${NC}"
echo " Check logs with: tail -f logs/mcp_server.log"
fi
cd "$PROJECT_DIR"
echo ""
# ===== 7. Start React Frontend =====
echo -e "${YELLOW}7. Starting React Frontend...${NC}"
if check_port 5173; then
echo -e " ${YELLOW}⚠ Port 5173 already in use, killing existing process...${NC}"
lsof -i :5173 | grep -v COMMAND | awk '{print $2}' | xargs kill -9 2>/dev/null || true
sleep 1
fi
cd "$PROJECT_DIR/frontend"
# Check if node_modules exists, install dependencies if not
if [ ! -d "node_modules" ]; then
echo " Installing frontend dependencies..."
npm install > "$PROJECT_DIR/logs/frontend.log" 2>&1
if [ $? -eq 0 ]; then
echo -e " ${GREEN}✓ Frontend dependencies installed${NC}"
else
echo -e " ${RED}❌ Failed to install frontend dependencies${NC}"
echo " Check logs with: tail -f logs/frontend.log"
cd "$PROJECT_DIR"
exit 1
fi
fi
nohup npm run dev -- --host 0.0.0.0 > "$PROJECT_DIR/logs/frontend.log" 2>&1 &
FRONTEND_PID=$!
echo " Frontend PID: $FRONTEND_PID (logging to logs/frontend.log)"
echo -n " Waiting for frontend to start"
if wait_for_port 5173 "Frontend"; then
:
else
echo -e " ${YELLOW}⚠ Could not verify frontend is running${NC}"
echo " Check logs with: tail -f logs/frontend.log"
fi
cd "$PROJECT_DIR"
echo ""
# ===== Summary =====
echo -e "${BLUE}=================================================="
echo "✅ All Services Started Successfully!"
echo "=================================================${NC}"
echo ""
echo -e "${GREEN}📡 Service URLs:${NC}"
echo " 🎨 Frontend: http://localhost:5173"
echo " 🔌 API Server: http://localhost:8051"
echo " 📚 API Docs: http://localhost:8051/docs"
echo ""
echo -e "${GREEN}🔧 Ollama:${NC}"
echo " Host: http://localhost:11434"
echo " Models: llama3.1:latest, nomic-embed-text:latest"
echo ""
echo -e "${GREEN}💾 Databases:${NC}"
echo " SQLite: data/claude-os.db"
echo " Redis: localhost:6379"
echo ""
echo -e "${GREEN}🤖 Real-Time Learning System:${NC}"
echo " RQ Workers: listening on 3 queues"
echo " Queues: claude-os:learning, prompts, ingest"
echo " Status: Active & always learning!"
echo ""
echo -e "${GREEN}📝 Log Files:${NC}"
echo " MCP Server: logs/mcp_server.log"
echo " Frontend: logs/frontend.log"
echo " RQ Workers: logs/rq_workers.log"
echo ""
echo -e "${GREEN}🛑 To Stop All Services:${NC}"
echo " ./stop_all_services.sh"
echo ""
echo -e "${GREEN}🔄 To Restart All Services:${NC}"
echo " ./restart_services.sh"
echo ""
echo -e "${YELLOW}💡 Tips:${NC}"
echo " - Frontend will auto-reload on code changes"
echo " - View logs: tail -f logs/mcp_server.log"
echo " - Backup DB: cp data/claude-os.db data/claude-os.db.backup"
echo " - Restart MCP: kill $MCP_PID && ./start_all_services.sh"
echo ""
echo -e "${GREEN}🚀 Enjoy building with Claude OS!${NC}"
echo ""