Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
| # 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 | |