#!/bin/bash # ============================================================ # Start Mission Control Dashboard + Ollama # # Usage: # bash start-dashboard.sh # start dashboard + ensure Ollama running # bash start-dashboard.sh stop # stop dashboard # bash start-dashboard.sh status # check status # ============================================================ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" DASHBOARD_DIR="$SCRIPT_DIR/dashboard" PORT=3000 OLLAMA_URL="http://localhost:11434" GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' ok() { echo -e "${GREEN}✓${NC} $1"; } warn() { echo -e "${YELLOW}⚠${NC} $1"; } fail() { echo -e "${RED}✗${NC} $1"; } case "${1:-start}" in stop) echo "Stopping dashboard..." PID=$(lsof -ti :$PORT 2>/dev/null) if [ -n "$PID" ]; then kill "$PID" 2>/dev/null ok "Dashboard stopped (PID $PID)" else warn "Dashboard not running on port $PORT" fi exit 0 ;; status) echo "=== Status ===" # Ollama if curl -s --max-time 2 "$OLLAMA_URL/api/tags" &>/dev/null; then MODELS=$(curl -s "$OLLAMA_URL/api/tags" | python3 -c "import sys,json; print(len(json.load(sys.stdin).get('models',[])))" 2>/dev/null || echo "?") ok "Ollama running ($MODELS models)" else fail "Ollama not running" fi # Dashboard if curl -s --max-time 2 "http://localhost:$PORT" &>/dev/null; then ok "Dashboard running at http://localhost:$PORT" else fail "Dashboard not running" fi exit 0 ;; start) echo "=== Starting Mission Control ===" echo "" # 1. Ensure Ollama is running if curl -s --max-time 2 "$OLLAMA_URL/api/tags" &>/dev/null; then ok "Ollama already running" else echo "Starting Ollama..." ollama serve &>/dev/null & sleep 2 if curl -s --max-time 2 "$OLLAMA_URL/api/tags" &>/dev/null; then ok "Ollama started" else fail "Could not start Ollama. Try: ollama serve" fi fi # 2. Check if dashboard already running if curl -s --max-time 2 "http://localhost:$PORT" &>/dev/null; then ok "Dashboard already running at http://localhost:$PORT" exit 0 fi # 3. Install deps if needed if [ ! -d "$DASHBOARD_DIR/node_modules" ]; then echo "Installing dependencies..." (cd "$DASHBOARD_DIR" && npm install --silent) ok "Dependencies installed" fi # 4. Start dashboard echo "Starting dashboard on port $PORT..." (cd "$DASHBOARD_DIR" && npm run dev &>/dev/null &) # Wait for it to be ready for i in $(seq 1 15); do if curl -s --max-time 1 "http://localhost:$PORT" &>/dev/null; then ok "Dashboard ready at http://localhost:$PORT" echo "" echo "Open: http://localhost:$PORT" echo "Stop: bash start-dashboard.sh stop" exit 0 fi sleep 1 done fail "Dashboard did not start within 15s. Check: cd dashboard && npm run dev" exit 1 ;; *) echo "Usage: bash start-dashboard.sh [start|stop|status]" exit 1 ;; esac