Files
OBIJupyterHub/start-jupyterhub.sh

112 lines
3.3 KiB
Bash
Raw Normal View History

2025-10-15 07:10:44 +02:00
#!/bin/bash
2025-10-14 17:40:41 +02:00
2025-10-15 07:10:44 +02:00
# JupyterHub startup script for labs
# Usage: ./start-jupyterhub.sh
2025-10-14 17:40:41 +02:00
2025-10-16 01:07:07 +02:00
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
DOCKER_DIR="${SCRIPT_DIR}/obijupyterhub/"
2025-10-15 07:10:44 +02:00
set -e # Stop on error
2025-10-14 17:40:41 +02:00
2025-10-15 07:10:44 +02:00
echo "🚀 Starting JupyterHub for Lab"
echo "=============================="
echo ""
2025-10-14 17:40:41 +02:00
2025-10-16 01:07:07 +02:00
# Compile the web site
echo ""
echo -e "${BLUE}🔨 Building the volume directories...${NC}"
pushd "${SCRIPT_DIR}/jupyterhub_volumes"
mkdir -p caddy
mkdir -p course/bin
mkdir -p course/R_packages
mkdir -p jupyterhub
mkdir -p shared
mkdir -p users
popd
2025-10-15 07:10:44 +02:00
# Colors for display
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
2025-10-14 17:40:41 +02:00
2025-10-16 01:07:07 +02:00
pushd "${DOCKER_DIR}"
2025-10-15 07:10:44 +02:00
# Check we're in the right directory
if [ ! -f "Dockerfile" ] || [ ! -f "docker-compose.yml" ]; then
echo "❌ Error: Run this script from the jupyterhub-tp/ directory"
exit 1
fi
2025-10-14 17:40:41 +02:00
2025-10-15 07:10:44 +02:00
# Stop existing containers
echo -e "${BLUE}📦 Stopping existing containers...${NC}"
docker-compose down 2>/dev/null || true
2025-10-14 17:40:41 +02:00
2025-10-15 07:10:44 +02:00
# Remove old student containers
echo -e "${BLUE}🧹 Cleaning up student containers...${NC}"
docker ps -aq --filter name=jupyter- | xargs -r docker rm -f 2>/dev/null || true
2025-10-14 17:40:41 +02:00
2025-10-15 07:10:44 +02:00
# Build student image
echo ""
echo -e "${BLUE}🔨 Building student image...${NC}"
docker build -t jupyterhub-student:latest -f Dockerfile .
# Build hub image
echo ""
echo -e "${BLUE}🔨 Building JupyterHub image...${NC}"
docker build -t jupyterhub-hub:latest -f Dockerfile.hub .
2025-10-16 01:07:07 +02:00
# Compile the web site
echo ""
echo -e "${BLUE}🔨 Building web site...${NC}"
pushd ../web_src
quarto render
python3 ../tools/generate_pages_json.py
popd
2025-10-15 07:10:44 +02:00
# Start the stack
echo ""
echo -e "${BLUE}🚀 Starting JupyterHub...${NC}"
2025-10-15 15:55:43 +02:00
docker-compose up -d --remove-orphans
2025-10-15 07:10:44 +02:00
# Wait for service to be ready
echo ""
echo -e "${YELLOW}⏳ Waiting for JupyterHub to start...${NC}"
sleep 3
2025-10-16 01:07:07 +02:00
popd
2025-10-15 07:10:44 +02:00
# Check that container is running
if docker ps | grep -q jupyterhub; then
echo ""
echo -e "${GREEN}✅ JupyterHub is running!${NC}"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
2025-10-15 07:15:05 +02:00
echo -e "${GREEN}🌐 JupyterHub available at: http://localhost:8888${NC}"
2025-10-15 07:10:44 +02:00
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "📝 Password: metabar2025"
echo "👥 Students can connect with any username"
echo ""
2025-10-15 07:15:05 +02:00
echo "🔑 Admin account:"
echo " Username: admin"
echo " Password: admin2025"
echo ""
2025-10-15 07:10:44 +02:00
echo "📂 Each student will have access to:"
2025-10-15 14:08:52 +02:00
echo " - work/ : personal workspace (everything saved)"
echo " - work/R_packages/ : personal R packages (writable)"
echo " - work/shared/ : shared workspace"
echo " - work/course/ : course files (read-only)"
echo " - work/course/R_packages/ : shared R packages by prof (read-only)"
echo " - work/course/bin/ : shared executables (in PATH)"
2025-10-15 07:10:44 +02:00
echo ""
echo "🔍 To view logs: docker-compose logs -f jupyterhub"
echo "🛑 To stop: docker-compose down"
echo ""
else
echo ""
echo -e "${YELLOW}⚠️ JupyterHub container doesn't seem to be starting${NC}"
echo "Check logs with: docker-compose logs jupyterhub"
exit 1
fi