diff --git a/launcher.bat b/launcher.bat new file mode 100644 index 000000000..6ecc13864 --- /dev/null +++ b/launcher.bat @@ -0,0 +1,164 @@ +@echo off +REM Open Notebook Launcher Script for Windows +REM This script launches all required services for Open Notebook + +setlocal enabledelayedexpansion + +echo. +echo ___ _ _ _ _ _ +echo / _ \ _ __ ___ _ __ ^| \ ^| ^| ___ ^| ^|_ ___^| ^|__ ___ ___ ^| ^| __ +echo ^| ^| ^| ^| '_ \ / _ \ '_ \^| \^| ^|/ _ \^| __/ _ \ '_ \ / _ \ / _ \^| ^|/ / +echo ^| ^|_^| ^| ^|_) ^| __/ ^| ^| ^| ^|\ ^| (_) ^| ^|^| __/ ^|_) ^| (_) ^| (_) ^| ^< +echo \___^| .__/ \___^|_^| ^|_^|_^| \_^|\___/ \__\___^|_.__/ \___/ \___/^|_^|\_\ +echo ^|_^| +echo. +echo Open Notebook Launcher +echo ====================== +echo. + +REM Check if we're in the right directory +if not exist "pyproject.toml" ( + echo [ERROR] Please run this script from the Open Notebook root directory + exit /b 1 +) + +REM Check for required tools +echo [INFO] Checking for required tools... + +REM Check for uv +where uv >nul 2>&1 +if %ERRORLEVEL% NEQ 0 ( + echo [ERROR] uv is not installed. + echo Please install uv from: https://astral.sh/uv + echo. + echo For Windows, run in PowerShell: + echo powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" + exit /b 1 +) +echo [OK] uv found + +REM Check for Node.js +where node >nul 2>&1 +if %ERRORLEVEL% NEQ 0 ( + echo [ERROR] Node.js is not installed. + echo Please install Node.js 18+ from: https://nodejs.org/ + exit /b 1 +) +for /f "tokens=*" %%i in ('node --version') do set NODE_VERSION=%%i +echo [OK] Node.js found (%NODE_VERSION%) + +REM Check for npm +where npm >nul 2>&1 +if %ERRORLEVEL% NEQ 0 ( + echo [ERROR] npm is not installed. + echo Please install Node.js which includes npm. + exit /b 1 +) +for /f "tokens=*" %%i in ('npm --version') do set NPM_VERSION=%%i +echo [OK] npm found (%NPM_VERSION%) + +REM Check for SurrealDB +where surreal >nul 2>&1 +if %ERRORLEVEL% NEQ 0 ( + echo [WARNING] SurrealDB is not installed. + echo Please install SurrealDB from: https://surrealdb.com/install + echo. + echo For Windows, run in PowerShell: + echo iwr https://windows.surrealdb.com -useb ^| iex + exit /b 1 +) +echo [OK] SurrealDB found + +REM Check for .env file +if not exist ".env" ( + echo [WARNING] .env file not found. + if exist ".env.example" ( + echo Creating .env from .env.example... + copy .env.example .env >nul + echo [OK] .env file created + echo [WARNING] Please edit .env and add your API keys before continuing + pause + ) else ( + echo [ERROR] .env.example not found + exit /b 1 + ) +) else ( + echo [OK] .env file found +) + +REM Install frontend dependencies if needed +if not exist "frontend\node_modules" ( + echo [INFO] Installing frontend dependencies... + cd frontend + call npm install + cd .. + echo [OK] Frontend dependencies installed +) else ( + echo [OK] Frontend dependencies already installed +) + +REM Create data directories if they don't exist +if not exist "notebook_data" mkdir notebook_data +if not exist "surreal_data" mkdir surreal_data + +echo. +echo [INFO] Starting Open Notebook services... +echo. + +REM Start SurrealDB +echo [INFO] Starting SurrealDB... +start "Open Notebook SurrealDB" /MIN cmd /c "surreal start --log info --user root --pass root memory > surreal.log 2>&1" +timeout /t 2 /nobreak >nul +echo [OK] SurrealDB started (Port: 8000) + +REM Start API +echo [INFO] Starting API backend... +start "Open Notebook API" /MIN cmd /c "uv run run_api.py > api.log 2>&1" +timeout /t 5 /nobreak >nul +echo [OK] API backend started (Port: 5055) + +REM Start background worker +echo [INFO] Starting background worker... +start "Open Notebook Worker" /MIN cmd /c "uv run --env-file .env surreal-commands-worker --import-modules commands > worker.log 2>&1" +timeout /t 2 /nobreak >nul +echo [OK] Background worker started + +REM Start frontend +echo [INFO] Starting Next.js frontend... +cd frontend +start "Open Notebook Frontend" /MIN cmd /c "npm run dev > ..\frontend.log 2>&1" +cd .. +timeout /t 5 /nobreak >nul +echo [OK] Next.js frontend started + +REM Display success message +echo. +echo ======================================== +echo Open Notebook is now running! +echo ======================================== +echo. +echo Access the application at: +echo Frontend: http://localhost:3000 +echo API: http://localhost:5055 +echo API Docs: http://localhost:5055/docs +echo. +echo Services are running in separate windows. +echo. +echo Log files: +echo - surreal.log +echo - api.log +echo - worker.log +echo - frontend.log +echo. +echo To stop all services: +echo 1. Close all Open Notebook command windows +echo 2. Or run: taskkill /F /FI "WINDOWTITLE eq Open Notebook*" +echo. +echo [INFO] Opening browser... +timeout /t 3 /nobreak >nul +start http://localhost:3000 + +echo. +echo Press any key to view the frontend log... +pause >nul +type frontend.log diff --git a/launcher.sh b/launcher.sh new file mode 100755 index 000000000..c5f63d55e --- /dev/null +++ b/launcher.sh @@ -0,0 +1,228 @@ +#!/bin/bash + +# Open Notebook Launcher Script +# This script launches all required services for Open Notebook + +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 + +# Function to print colored output +print_info() { + echo -e "${BLUE}ℹ${NC} $1" +} + +print_success() { + echo -e "${GREEN}✓${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}⚠${NC} $1" +} + +print_error() { + echo -e "${RED}✗${NC} $1" +} + +# Banner +echo -e "${BLUE}" +cat << "EOF" + ___ _ _ _ _ _ +/ _ \ _ __ ___ _ __ | \ | | ___ | |_ ___| |__ ___ ___ | | __ +| | | | '_ \ / _ \ '_ \| \| |/ _ \| __/ _ \ '_ \ / _ \ / _ \| |/ / +| |_| | |_) | __/ | | | |\ | (_) | || __/ |_) | (_) | (_) | < +\___/| .__/ \___|_| |_|_| \_|\___/ \__\___|_.__/ \___/ \___/|_|\_\ + |_| +EOF +echo -e "${NC}" +echo "Open Notebook Launcher" +echo "======================" +echo "" + +# Check if we're in the right directory +if [ ! -f "pyproject.toml" ]; then + print_error "Please run this script from the Open Notebook root directory" + exit 1 +fi + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Check for required tools +print_info "Checking for required tools..." + +if ! command_exists uv; then + print_error "uv is not installed. Installing uv..." + curl -LsSf https://astral.sh/uv/install.sh | sh + export PATH="$HOME/.local/bin:$PATH" +fi +print_success "uv found" + +if ! command_exists node; then + print_error "Node.js is not installed. Please install Node.js 18+ from https://nodejs.org/" + exit 1 +fi +print_success "Node.js found ($(node --version))" + +if ! command_exists npm; then + print_error "npm is not installed. Please install Node.js which includes npm." + exit 1 +fi +print_success "npm found ($(npm --version))" + +# Check for SurrealDB +if ! command_exists surreal; then + print_warning "SurrealDB is not installed. Installing SurrealDB..." + curl -sSf https://install.surrealdb.com | sh + export PATH="/usr/local/bin:$PATH" + print_success "SurrealDB installed" +else + print_success "SurrealDB found ($(surreal version | head -1))" +fi + +# Check for .env file +if [ ! -f ".env" ]; then + print_warning ".env file not found. Creating from .env.example..." + if [ -f ".env.example" ]; then + cp .env.example .env + print_success ".env file created" + print_warning "Please edit .env and add your API keys before continuing" + read -p "Press Enter to continue or Ctrl+C to exit and edit .env..." + else + print_error ".env.example not found" + exit 1 + fi +else + print_success ".env file found" +fi + +# Install frontend dependencies if needed +if [ ! -d "frontend/node_modules" ]; then + print_info "Installing frontend dependencies..." + cd frontend + npm install + cd .. + print_success "Frontend dependencies installed" +else + print_success "Frontend dependencies already installed" +fi + +# Create data directories if they don't exist +mkdir -p notebook_data surreal_data + +# Function to cleanup on exit +cleanup() { + echo "" + print_info "Shutting down Open Notebook services..." + pkill -f "surreal start" 2>/dev/null || true + pkill -f "run_api.py" 2>/dev/null || true + pkill -f "uvicorn api.main:app" 2>/dev/null || true + pkill -f "surreal-commands-worker" 2>/dev/null || true + pkill -f "next dev" 2>/dev/null || true + sleep 2 + print_success "All services stopped" + exit 0 +} + +# Register cleanup function +trap cleanup EXIT INT TERM + +# Start services +echo "" +print_info "Starting Open Notebook services..." +echo "" + +# Start SurrealDB +print_info "Starting SurrealDB..." +surreal start --log info --user root --pass root memory > /tmp/surrealdb.log 2>&1 & +SURREAL_PID=$! +sleep 2 + +if ps -p $SURREAL_PID > /dev/null; then + print_success "SurrealDB started (PID: $SURREAL_PID, Port: 8000)" +else + print_error "Failed to start SurrealDB" + exit 1 +fi + +# Start API +print_info "Starting API backend..." +uv run run_api.py > /tmp/api.log 2>&1 & +API_PID=$! +sleep 5 + +if ps -p $API_PID > /dev/null; then + print_success "API backend started (PID: $API_PID, Port: 5055)" +else + print_error "Failed to start API backend. Check /tmp/api.log for details" + exit 1 +fi + +# Start background worker +print_info "Starting background worker..." +uv run --env-file .env surreal-commands-worker --import-modules commands > /tmp/worker.log 2>&1 & +WORKER_PID=$! +sleep 2 + +if ps -p $WORKER_PID > /dev/null; then + print_success "Background worker started (PID: $WORKER_PID)" +else + print_error "Failed to start background worker. Check /tmp/worker.log for details" + exit 1 +fi + +# Start frontend +print_info "Starting Next.js frontend..." +cd frontend +npm run dev > /tmp/frontend.log 2>&1 & +FRONTEND_PID=$! +cd .. +sleep 5 + +if ps -p $FRONTEND_PID > /dev/null; then + # Try to detect the port +FRONTEND_PORT=$(grep -Eo "localhost:[0-9]+" /tmp/frontend.log | head -1 | cut -d: -f2) + if [ -z "$FRONTEND_PORT" ]; then + FRONTEND_PORT="3000" + fi + print_success "Next.js frontend started (PID: $FRONTEND_PID, Port: $FRONTEND_PORT)" +else + print_error "Failed to start frontend. Check /tmp/frontend.log for details" + exit 1 +fi + +# Display success message +echo "" +echo -e "${GREEN}========================================${NC}" +echo -e "${GREEN} Open Notebook is now running!${NC}" +echo -e "${GREEN}========================================${NC}" +echo "" +echo "Access the application at:" +echo -e " ${BLUE}➜${NC} Frontend: ${GREEN}http://localhost:${FRONTEND_PORT}${NC}" +echo -e " ${BLUE}➜${NC} API: ${GREEN}http://localhost:5055${NC}" +echo -e " ${BLUE}➜${NC} API Docs: ${GREEN}http://localhost:5055/docs${NC}" +echo "" +echo "Process IDs:" +echo " • SurrealDB: $SURREAL_PID" +echo " • API: $API_PID" +echo " • Worker: $WORKER_PID" +echo " • Frontend: $FRONTEND_PID" +echo "" +echo "Logs are available in /tmp/:" +echo " • /tmp/surrealdb.log" +echo " • /tmp/api.log" +echo " • /tmp/worker.log" +echo " • /tmp/frontend.log" +echo "" +print_warning "Press Ctrl+C to stop all services" +echo "" + +# Keep script running and display logs +tail -f /tmp/frontend.log