latest
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
# ClassroomCopilot Startup Script
|
||||
# Usage: ./start.sh [start_mode]
|
||||
# start_mode options: init, dev, prod
|
||||
# start_mode options: infra, demo-school, demo-users, gais-data, full, dev, prod
|
||||
|
||||
set -e
|
||||
|
||||
@@ -10,18 +10,29 @@ set -e
|
||||
show_help() {
|
||||
echo "ClassroomCopilot Startup Script"
|
||||
echo ""
|
||||
echo "Usage: ./start.sh [start_mode]"
|
||||
echo "Usage: ./start.sh [start_mode] [--yes]"
|
||||
echo ""
|
||||
echo "Start modes:"
|
||||
echo " init - Run initialization scripts (database setup, etc.)"
|
||||
echo " dev - Run development server with auto-reload"
|
||||
echo " prod - Run production server (for Docker/containerized deployment)"
|
||||
echo " infra - Setup infrastructure (Neo4j schema, calendar, Supabase buckets)"
|
||||
echo " demo-school - Create demo school (KevlarAI)"
|
||||
echo " demo-users - Create demo users"
|
||||
echo " gais-data - Import GAIS data (Edubase, etc.)"
|
||||
echo " full - Run full initialization (infra → demo-school → demo-users → gais-data)"
|
||||
echo " nuke - 💥 NUKE Redis - Clear all queue data for fresh start"
|
||||
echo " dev - Run development server with auto-reload"
|
||||
echo " prod - Run production server (for Docker/containerized deployment)"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " ./start.sh # Run in dev mode (default)"
|
||||
echo " ./start.sh init # Run initialization only"
|
||||
echo " ./start.sh dev # Run development server"
|
||||
echo " ./start.sh prod # Run production server"
|
||||
echo " ./start.sh # Run in dev mode (default)"
|
||||
echo " ./start.sh infra # Setup infrastructure"
|
||||
echo " ./start.sh demo-school # Create demo school"
|
||||
echo " ./start.sh demo-users # Create demo users"
|
||||
echo " ./start.sh gais-data # Import GAIS data"
|
||||
echo " ./start.sh full # Run full initialization"
|
||||
echo " ./start.sh full --yes # Run full initialization without prompts"
|
||||
echo " ./start.sh nuke # 💥 NUKE Redis completely"
|
||||
echo " ./start.sh dev # Run development server"
|
||||
echo " ./start.sh prod # Run production server"
|
||||
echo ""
|
||||
echo "For more information, see README_STARTUP.md"
|
||||
}
|
||||
@@ -35,6 +46,12 @@ fi
|
||||
# Default to dev mode if no argument provided
|
||||
START_MODE=${1:-dev}
|
||||
|
||||
# Non-interactive flag
|
||||
AUTO_YES=false
|
||||
if [[ "$2" == "--yes" || "$2" == "-y" ]]; then
|
||||
AUTO_YES=true
|
||||
fi
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
@@ -90,33 +107,223 @@ check_env() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run initialization
|
||||
run_init() {
|
||||
print_status "Running initialization mode..."
|
||||
print_status "This will set up databases and initial data structures."
|
||||
# Function to run infrastructure setup
|
||||
run_infra() {
|
||||
print_status "Running infrastructure setup mode..."
|
||||
print_status "This will set up Neo4j schema, calendar structure, and Supabase buckets."
|
||||
|
||||
# Check if we should proceed
|
||||
read -p "Do you want to continue with initialization? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Initialization cancelled."
|
||||
exit 0
|
||||
if [[ "$AUTO_YES" != true ]]; then
|
||||
read -p "Do you want to continue with infrastructure setup? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Infrastructure setup cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_status "Starting initialization process..."
|
||||
$PYTHON_CMD main.py --mode init
|
||||
print_status "Starting infrastructure setup process..."
|
||||
$PYTHON_CMD main.py --mode infra
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Initialization completed successfully!"
|
||||
print_success "Infrastructure setup completed successfully!"
|
||||
else
|
||||
print_error "Initialization failed!"
|
||||
print_error "Infrastructure setup failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run demo school creation
|
||||
run_demo_school() {
|
||||
print_status "Running demo school creation mode..."
|
||||
print_status "This will create the KevlarAI demo school."
|
||||
|
||||
# Check if we should proceed
|
||||
if [[ "$AUTO_YES" != true ]]; then
|
||||
read -p "Do you want to continue with demo school creation? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Demo school creation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_status "Starting demo school creation process..."
|
||||
$PYTHON_CMD main.py --mode demo-school
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Demo school creation completed successfully!"
|
||||
else
|
||||
print_error "Demo school creation failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run demo users creation
|
||||
run_demo_users() {
|
||||
print_status "Running demo users creation mode..."
|
||||
print_status "This will create demo users for testing."
|
||||
|
||||
# Check if we should proceed
|
||||
if [[ "$AUTO_YES" != true ]]; then
|
||||
read -p "Do you want to continue with demo users creation? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Demo users creation cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_status "Starting demo users creation process..."
|
||||
$PYTHON_CMD main.py --mode demo-users
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "Demo users creation completed successfully!"
|
||||
else
|
||||
print_error "Demo users creation failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run GAIS data import
|
||||
run_gais_data() {
|
||||
print_status "Running GAIS data import mode..."
|
||||
print_status "This will import publicly available school databases (Edubase, etc.) into Neo4j."
|
||||
|
||||
# Check if we should proceed
|
||||
if [[ "$AUTO_YES" != true ]]; then
|
||||
read -p "Do you want to continue with GAIS data import? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "GAIS data import cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_status "Starting GAIS data import process..."
|
||||
$PYTHON_CMD main.py --mode gais-data
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "GAIS data import completed successfully!"
|
||||
else
|
||||
print_error "GAIS data import failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to nuke Redis - clear all queue data
|
||||
run_nuke() {
|
||||
print_status "💥 NUKING Redis - Clear all queue data for fresh start..."
|
||||
print_warning "This will DELETE ALL Redis data including queues, tasks, and metrics."
|
||||
|
||||
# Check if we should proceed
|
||||
if [[ "$AUTO_YES" != true ]]; then
|
||||
read -p "Are you SURE you want to nuke Redis? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Redis nuke cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
print_status "Nuking Redis..."
|
||||
|
||||
# Kill any running servers first
|
||||
print_status "Stopping any running API servers..."
|
||||
pkill -f "python.*main\.py" 2>/dev/null || true
|
||||
pkill -f "uvicorn" 2>/dev/null || true
|
||||
sleep 2
|
||||
|
||||
# Clear Redis using new manager
|
||||
$PYTHON_CMD -c "
|
||||
from modules.redis_manager import get_redis_manager
|
||||
import redis, os
|
||||
|
||||
try:
|
||||
# Nuke all environments
|
||||
total_cleared = 0
|
||||
for env in ['dev', 'prod', 'test']:
|
||||
try:
|
||||
manager = get_redis_manager(env)
|
||||
if manager.ensure_service_running() and manager.connect():
|
||||
all_keys = manager.client.keys('*')
|
||||
if all_keys:
|
||||
manager.client.flushdb()
|
||||
total_cleared += len(all_keys)
|
||||
print(f'💥 NUKED {env.upper()}: Cleared {len(all_keys)} keys (db={manager.config.db})')
|
||||
else:
|
||||
print(f'✅ {env.upper()}: Already empty (db={manager.config.db})')
|
||||
manager.client.close()
|
||||
except Exception as e:
|
||||
print(f'⚠️ Warning: Could not clear {env} environment: {e}')
|
||||
|
||||
print(f'💥 TOTAL NUKED: {total_cleared} keys across all environments')
|
||||
print('🧹 Redis completely reset - ready for clean start!')
|
||||
except Exception as e:
|
||||
print(f'❌ Failed to connect to Redis: {e}')
|
||||
exit(1)
|
||||
"
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
print_success "💥 Redis NUKED successfully! Fresh slate ready."
|
||||
else
|
||||
print_error "Redis nuke failed!"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to run full initialization (all steps in order)
|
||||
run_full() {
|
||||
print_status "Running full initialization (infra → demo-school → demo-users → gais-data)..."
|
||||
|
||||
# Single confirmation for the whole flow
|
||||
if [[ "$AUTO_YES" != true ]]; then
|
||||
read -p "Do you want to run the full initialization? (y/N): " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
print_status "Full initialization cancelled."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# Run infra
|
||||
run_infra || { print_error "Full init aborted during infra."; exit 1; }
|
||||
|
||||
# Run demo school
|
||||
run_demo_school || { print_error "Full init aborted during demo-school."; exit 1; }
|
||||
|
||||
# Run demo users
|
||||
run_demo_users || { print_error "Full init aborted during demo-users."; exit 1; }
|
||||
|
||||
# Run GAIS data import
|
||||
run_gais_data || { print_error "Full init aborted during gais-data."; exit 1; }
|
||||
|
||||
print_success "Full initialization completed successfully!"
|
||||
}
|
||||
|
||||
# Function to run development mode
|
||||
run_dev() {
|
||||
print_status "Running development mode..."
|
||||
|
||||
# Stop any running API servers
|
||||
print_status "🛑 Stopping any running API servers..."
|
||||
pkill -f "python.*main\.py" 2>/dev/null || true
|
||||
pkill -f "uvicorn" 2>/dev/null || true
|
||||
sleep 1
|
||||
|
||||
# Ensure Redis service is running and will auto-clear dev database
|
||||
print_status "🔧 Ensuring Redis service is running for development..."
|
||||
|
||||
$PYTHON_CMD -c "
|
||||
from modules.redis_manager import ensure_redis_running
|
||||
if ensure_redis_running('dev'):
|
||||
print('✅ Redis service ready for development (will auto-clear db=0)')
|
||||
else:
|
||||
print('❌ Failed to start Redis service')
|
||||
exit(1)
|
||||
" || { print_error "Redis setup failed"; exit 1; }
|
||||
|
||||
print_status "🎯 Development mode will use clean Redis database (db=0)..."
|
||||
print_status "Starting uvicorn server with auto-reload..."
|
||||
|
||||
export BACKEND_DEV_MODE=true
|
||||
@@ -133,6 +340,19 @@ run_dev() {
|
||||
# Function to run production mode
|
||||
run_prod() {
|
||||
print_status "Running production mode..."
|
||||
|
||||
# Ensure Redis service is running with data recovery
|
||||
print_status "🏰 Ensuring Redis service is running for production..."
|
||||
|
||||
$PYTHON_CMD -c "
|
||||
from modules.redis_manager import ensure_redis_running
|
||||
if ensure_redis_running('prod'):
|
||||
print('✅ Redis service ready for production (db=1, with task recovery)')
|
||||
else:
|
||||
print('❌ Failed to start Redis service')
|
||||
exit(1)
|
||||
" || { print_error "Redis setup failed"; exit 1; }
|
||||
|
||||
print_status "Starting uvicorn server in production mode..."
|
||||
|
||||
export BACKEND_DEV_MODE=false
|
||||
@@ -160,8 +380,23 @@ main() {
|
||||
|
||||
# Execute based on start mode
|
||||
case $START_MODE in
|
||||
"init")
|
||||
run_init
|
||||
"infra")
|
||||
run_infra
|
||||
;;
|
||||
"demo-school")
|
||||
run_demo_school
|
||||
;;
|
||||
"demo-users")
|
||||
run_demo_users
|
||||
;;
|
||||
"gais-data")
|
||||
run_gais_data
|
||||
;;
|
||||
"full")
|
||||
run_full
|
||||
;;
|
||||
"nuke")
|
||||
run_nuke
|
||||
;;
|
||||
"dev")
|
||||
run_dev
|
||||
@@ -171,7 +406,7 @@ main() {
|
||||
;;
|
||||
*)
|
||||
print_error "Invalid start mode: $START_MODE"
|
||||
print_status "Valid modes: init, dev, prod"
|
||||
print_status "Valid modes: infra, demo-school, demo-users, gais-data, nuke, dev, prod"
|
||||
print_status "Usage: ./start.sh [start_mode]"
|
||||
print_status "Use './start.sh --help' for more information"
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user