Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 7,155 Bytes
61d29fc | 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 | #!/bin/bash
# Start All Services for Open Navigator
# This script launches the API backend, React dashboard, and Docusaurus docs
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"
echo "๐ Starting Open Navigator"
echo "=========================================="
echo ""
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Check if dependencies are installed
echo -e "${BLUE}Checking dependencies...${NC}"
if [ ! -d ".venv" ]; then
echo -e "${YELLOW}โ ๏ธ Virtual environment not found. Run ./install.sh first${NC}"
exit 1
fi
if [ ! -d "frontend/node_modules" ]; then
echo -e "${YELLOW}Installing frontend dependencies...${NC}"
cd frontend && npm install && cd ..
fi
if [ ! -d "website/node_modules" ]; then
echo -e "${YELLOW}Installing documentation site dependencies...${NC}"
cd website && npm install && cd ..
fi
echo -e "${GREEN}โ
Dependencies OK${NC}"
echo ""
# Function to kill processes on required ports
kill_port_processes() {
local ports=(3000 5173 8000)
echo -e "${BLUE}Checking for processes on ports...${NC}"
for port in "${ports[@]}"; do
local pid=$(lsof -ti:$port 2>/dev/null)
if [ ! -z "$pid" ]; then
echo -e "${YELLOW}โ ๏ธ Killing process on port $port (PID: $pid)${NC}"
kill -9 $pid 2>/dev/null || true
sleep 0.5
fi
done
echo -e "${GREEN}โ
Ports cleared${NC}"
echo ""
}
# Function to check if tmux is available
has_tmux() {
command -v tmux >/dev/null 2>&1
}
# Kill any processes on the ports we need
kill_port_processes
# Function to start with tmux (preferred)
start_with_tmux() {
SESSION="open-navigator"
# Kill existing session if it exists
tmux kill-session -t $SESSION 2>/dev/null || true
echo -e "${BLUE}Starting services in tmux session: $SESSION${NC}"
echo ""
# Create new session with first window for API
tmux new-session -d -s $SESSION -n "API" "cd '$SCRIPT_DIR' && source .venv/bin/activate && echo '๐ฅ Starting API Backend...' && python main.py serve; read"
# Create window for Dashboard
tmux new-window -t $SESSION -n "Dashboard" "cd '$SCRIPT_DIR/frontend' && echo 'โ๏ธ Starting React Dashboard...' && npm run dev; read"
# Create window for Docs
tmux new-window -t $SESSION -n "Docs" "cd '$SCRIPT_DIR/website' && echo '๐ Starting Documentation Site...' && npm start; read"
# Create window for logs/commands
tmux new-window -t $SESSION -n "Shell" "cd '$SCRIPT_DIR' && source .venv/bin/activate && bash"
# Select first window
tmux select-window -t $SESSION:0
echo -e "${GREEN}โ
All services started in tmux!${NC}"
echo ""
echo "๐ก Services:"
echo " โข ๐ MAIN APP: http://localhost:5173 (Open Navigator - search, filters, heatmap)"
echo " โข ๐ Documentation: http://localhost:3000 (Docusaurus - guides & tutorials)"
echo " โข ๐ฅ API Backend: http://localhost:8000 (FastAPI)"
echo " โข ๐ API Docs: http://localhost:8000/docs"
echo ""
echo "๐ก Start here: http://localhost:5173 (Open Navigator - MAIN APPLICATION)"
echo ""
echo "๐ฎ tmux Controls:"
echo " โข Attach to session: tmux attach -t $SESSION"
echo " โข Switch windows: Ctrl+b then 0/1/2/3"
echo " โข Detach: Ctrl+b then d"
echo " โข Stop all: tmux kill-session -t $SESSION"
echo ""
# Ask if user wants to attach
read -p "Attach to tmux session now? [Y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
# Open browser before attaching
if command -v xdg-open >/dev/null 2>&1; then
sleep 2 # Give services time to start
xdg-open http://localhost:5173 2>/dev/null &
fi
tmux attach -t $SESSION
else
# Offer to open browser if not attaching
if command -v xdg-open >/dev/null 2>&1; then
read -p "Open main application in browser? [Y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
sleep 2
xdg-open http://localhost:5173 2>/dev/null &
fi
fi
fi
}
# Function to start without tmux (fallback)
start_without_tmux() {
echo -e "${YELLOW}tmux not found. Starting services in background...${NC}"
echo -e "${YELLOW}(Install tmux for better experience: sudo apt install tmux)${NC}"
echo ""
# Create log directory
mkdir -p logs
# Start API
echo -e "${BLUE}Starting API Backend...${NC}"
source .venv/bin/activate
nohup python main.py serve > logs/api.log 2>&1 &
API_PID=$!
echo $API_PID > logs/api.pid
echo -e "${GREEN}โ
API started (PID: $API_PID)${NC}"
# Start Dashboard
echo -e "${BLUE}Starting React Dashboard...${NC}"
cd frontend
nohup npm run dev > ../logs/dashboard.log 2>&1 &
DASHBOARD_PID=$!
echo $DASHBOARD_PID > ../logs/dashboard.pid
cd ..
echo -e "${GREEN}โ
Dashboard started (PID: $DASHBOARD_PID)${NC}"
# Start Docs
echo -e "${BLUE}Starting Documentation Site...${NC}"
cd website
nohup npm start > ../logs/docs.log 2>&1 &
DOCS_PID=$!
echo $DOCS_PID > ../logs/docs.pid
cd ..
echo -e "${GREEN}โ
Docs started (PID: $DOCS_PID)${NC}"
echo ""
echo -e "${GREEN}โ
All services started!${NC}"
echo ""
echo "๐ก Services:"
echo " โข ๐ MAIN APP: http://localhost:5173 (Open Navigator - search, filters, heatmap)"
echo " โข ๐ Documentation: http://localhost:3000 (Docusaurus - guides & tutorials)"
echo " โข ๐ฅ API Backend: http://localhost:8000 (FastAPI)"
echo " โข ๐ API Docs: http://localhost:8000/docs"
echo ""
echo "๐ก Start here: http://localhost:5173 (Open Navigator - MAIN APPLICATION)"
echo ""
echo "๐ Logs:"
echo " โข API: tail -f logs/api.log"
echo " โข Dashboard: tail -f logs/dashboard.log"
echo " โข Docs: tail -f logs/docs.log"
echo ""
echo "๐ To stop all services:"
echo " ./stop-all.sh"
echo " (or kill \$(cat logs/*.pid))"
echo ""
# Wait a bit for services to start
echo "โณ Waiting for services to initialize..."
sleep 5
echo ""
echo "๐ Open Navigator is ready!"
echo ""
echo "๐ MAIN APP: http://localhost:5173 (Open Navigator - search, filters, heatmap)"
echo "๐ Documentation: http://localhost:3000 (guides, API docs, tutorials)"
echo "๐ฅ API: http://localhost:8000/docs (FastAPI interactive docs)"
echo ""
# Offer to open browser
if command -v xdg-open >/dev/null 2>&1; then
read -p "Open main application in browser? [Y/n] " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
sleep 2 # Give services a moment to fully start
xdg-open http://localhost:5173 2>/dev/null &
fi
fi
}
# Main execution
if has_tmux; then
start_with_tmux
else
start_without_tmux
fi
|