Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions template/start-code-interpreter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

echo "Waiting for Jupyter server to be ready..."
until curl -s -o /dev/null -w '%{http_code}' http://localhost:8888/api/status | grep -q '200'; do
sleep 0.5
done
echo "Jupyter server is ready, starting Code Interpreter..."

exec /root/.server/.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
5 changes: 5 additions & 0 deletions template/start-jupyter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

trap 'echo "Jupyter exited, killing code-interpreter..."; pkill -f "uvicorn main:app"' EXIT

exec /usr/local/bin/jupyter server --IdentityProvider.token=""
20 changes: 1 addition & 19 deletions template/start-up.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
#!/bin/bash

function start_jupyter_server() {
counter=0
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8888/api/status")
while [[ ${response} -ne 200 ]]; do
let counter++
if ((counter % 20 == 0)); then
echo "Waiting for Jupyter Server to start..."
sleep 0.1
fi

response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8888/api/status")
done

cd /root/.server/
.venv/bin/uvicorn main:app --host 0.0.0.0 --port 49999 --workers 1 --no-access-log --no-use-colors --timeout-keep-alive 640
}

echo "Starting Code Interpreter server..."
start_jupyter_server &
MATPLOTLIBRC=/root/.config/matplotlib/.matplotlibrc jupyter server --IdentityProvider.token="" >/dev/null 2>&1
supervisord -c /etc/supervisord.conf
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could do this as a start command, so it's obvious?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason I left it there is so you can track the changes to the command in git history

24 changes: 24 additions & 0 deletions template/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisord.log
pidfile=/var/run/supervisord.pid

[program:jupyter]
command=/root/.jupyter/start-jupyter.sh
environment=MATPLOTLIBRC="/root/.config/matplotlib/.matplotlibrc"
stdout_logfile=/dev/null
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0
autorestart=true
priority=10
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing startsecs=0 risks FATAL state for jupyter

Medium Severity

The [program:jupyter] section relies on the default startsecs=1, meaning if the start-jupyter.sh wrapper (including jupyter startup and the subsequent kill cleanup) completes in under one second, supervisord treats it as a failed start. After three such rapid failures (default startretries=3), supervisord moves jupyter to FATAL state and stops restarting it entirely — undermining the core purpose of this PR. This was flagged in the PR review but appears unaddressed in the final config.

Fix in Cursor Fix in Web


[program:code-interpreter]
command=/root/.jupyter/start-code-interpreter.sh
directory=/root/.server
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
stderr_logfile=/dev/fd/1
stderr_logfile_maxbytes=0
autorestart=true
priority=20
startsecs=0
9 changes: 8 additions & 1 deletion template/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def make_template(
"sudo",
"fonts-noto-cjk",
"ca-certificates",
"supervisor",
]
)
.run_cmd("curl -fsSL https://deb.nodesource.com/setup_20.x | bash -")
Expand Down Expand Up @@ -121,11 +122,17 @@ def make_template(
template = (
template.copy("matplotlibrc", ".config/matplotlib/.matplotlibrc")
.copy("start-up.sh", ".jupyter/start-up.sh")
.run_cmd("chmod +x .jupyter/start-up.sh")
.copy("start-code-interpreter.sh", ".jupyter/start-code-interpreter.sh")
.copy("start-jupyter.sh", ".jupyter/start-jupyter.sh")
.run_cmd(
"chmod +x .jupyter/start-code-interpreter.sh .jupyter/start-up.sh .jupyter/start-jupyter.sh"
)
.copy("jupyter_server_config.py", ".jupyter/")
.make_dir(".ipython/profile_default/startup")
.copy("ipython_kernel_config.py", ".ipython/profile_default/")
.copy("startup_scripts", ".ipython/profile_default/startup")
# Install supervisord config
.copy("supervisord.conf", "/etc/supervisord.conf")
)

if is_docker:
Expand Down
Loading