22
33# Function to check if Jupyter is ready
44check_jupyter_ready () {
5- curl -s http://localhost:8888/api > /dev/null 2>&1
5+ # Check if API is responsive and kernelspecs are available
6+ curl -s http://localhost:8888/api/kernelspecs > /dev/null 2>&1
67}
78
89# Function to notify Bun server that Jupyter is ready
@@ -12,19 +13,10 @@ notify_jupyter_ready() {
1213 echo " [Startup] Jupyter is ready, notified Bun server"
1314}
1415
15- # Start Jupyter notebook server in background
16+ # Start Jupyter server in background
1617echo " [Startup] Starting Jupyter server..."
17- jupyter notebook \
18- --ip=0.0.0.0 \
19- --port=8888 \
20- --no-browser \
21- --allow-root \
22- --NotebookApp.token=' ' \
23- --NotebookApp.password=' ' \
24- --NotebookApp.allow_origin=' *' \
25- --NotebookApp.disable_check_xsrf=True \
26- --NotebookApp.allow_remote_access=True \
27- --NotebookApp.allow_credentials=True \
18+ jupyter server \
19+ --config=/container-server/jupyter_config.py \
2820 > /tmp/jupyter.log 2>&1 &
2921
3022JUPYTER_PID=$!
@@ -37,40 +29,49 @@ BUN_PID=$!
3729# Monitor Jupyter readiness in background
3830(
3931 echo " [Startup] Monitoring Jupyter readiness in background..."
40- MAX_ATTEMPTS=30
32+ MAX_ATTEMPTS=60
4133 ATTEMPT=0
42- DELAY=0.5
43- MAX_DELAY=5
44-
34+
35+ # Track start time for reporting
36+ START_TIME=$( date +%s.%N)
37+
4538 while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
4639 if check_jupyter_ready; then
4740 notify_jupyter_ready
48- echo " [Startup] Jupyter server is ready after $ATTEMPT attempts"
41+ END_TIME=$( date +%s.%N)
42+ ELAPSED=$( awk " BEGIN {printf \" %.2f\" , $END_TIME - $START_TIME }" )
43+ echo " [Startup] Jupyter server is ready after $ELAPSED seconds ($ATTEMPT attempts)"
4944 break
5045 fi
51-
46+
5247 # Check if Jupyter process is still running
5348 if ! kill -0 $JUPYTER_PID 2> /dev/null; then
5449 echo " [Startup] WARNING: Jupyter process died. Check /tmp/jupyter.log for details"
5550 cat /tmp/jupyter.log
5651 # Don't exit - let Bun server continue running in degraded mode
5752 break
5853 fi
59-
54+
6055 ATTEMPT=$(( ATTEMPT + 1 ))
61- echo " [Startup] Jupyter not ready yet (attempt $ATTEMPT /$MAX_ATTEMPTS , delay ${DELAY} s)"
62-
63- # Sleep with exponential backoff
64- sleep $DELAY
65-
66- # Increase delay exponentially with jitter, cap at MAX_DELAY
67- DELAY=$( awk " BEGIN {printf \" %.2f\" , $DELAY * 1.5 + (rand() * 0.5)}" )
68- # Use awk for comparison since bc might not be available
69- if [ $( awk " BEGIN {print ($DELAY > $MAX_DELAY )}" ) -eq 1 ]; then
70- DELAY=$MAX_DELAY
56+
57+ # Start with faster checks
58+ if [ $ATTEMPT -eq 1 ]; then
59+ DELAY=0.5 # Start at 0.5s
60+ else
61+ # Exponential backoff with 1.3x multiplier (less aggressive than 1.5x)
62+ DELAY=$( awk " BEGIN {printf \" %.2f\" , $DELAY * 1.3}" )
63+ # Cap at 2s max (instead of 5s)
64+ if [ $( awk " BEGIN {print ($DELAY > 2)}" ) -eq 1 ]; then
65+ DELAY=2
66+ fi
7167 fi
68+
69+ # Log with current delay for transparency
70+ echo " [Startup] Jupyter not ready yet (attempt $ATTEMPT /$MAX_ATTEMPTS , next check in ${DELAY} s)"
71+
72+ sleep $DELAY
7273 done
73-
74+
7475 if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then
7576 echo " [Startup] WARNING: Jupyter failed to become ready within attempts"
7677 echo " [Startup] Jupyter logs:"
@@ -80,4 +81,4 @@ BUN_PID=$!
8081) &
8182
8283# Wait for Bun server (main process)
83- wait $BUN_PID
84+ wait $BUN_PID
0 commit comments