Skip to content

Commit 92f631b

Browse files
authored
migrate Jupyter Notebook to uv-based installation with update support (#5320)
1 parent 9133782 commit 92f631b

File tree

2 files changed

+60
-20
lines changed

2 files changed

+60
-20
lines changed

ct/jupyternotebook.sh

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,53 @@ color
2020
catch_errors
2121

2222
function update_script() {
23-
header_info
24-
check_container_storage
25-
check_container_resources
26-
27-
msg_info "Updating ${APP} LXC"
28-
$STD apt-get update
29-
$STD apt-get install -y upgrade
30-
$STD pip3 install jupyter --upgrade
31-
msg_ok "Updated Successfully"
32-
exit
23+
header_info
24+
check_container_storage
25+
check_container_resources
26+
27+
INSTALL_DIR="/opt/jupyter"
28+
VENV_PYTHON="${INSTALL_DIR}/.venv/bin/python"
29+
VENV_JUPYTER="${INSTALL_DIR}/.venv/bin/jupyter"
30+
SERVICE_FILE="/etc/systemd/system/jupyternotebook.service"
31+
32+
if [[ ! -x "$VENV_JUPYTER" ]]; then
33+
msg_info "Migrating to uv venv"
34+
PYTHON_VERSION="3.12" setup_uv
35+
mkdir -p "$INSTALL_DIR"
36+
cd "$INSTALL_DIR"
37+
$STD uv venv .venv
38+
$STD "$VENV_PYTHON" -m ensurepip --upgrade
39+
$STD "$VENV_PYTHON" -m pip install --upgrade pip
40+
$STD "$VENV_PYTHON" -m pip install jupyter
41+
msg_ok "Migrated to uv and installed Jupyter"
42+
else
43+
msg_info "Updating Jupyter"
44+
$STD "$VENV_PYTHON" -m pip install --upgrade pip
45+
$STD "$VENV_PYTHON" -m pip install --upgrade jupyter
46+
msg_ok "Jupyter updated"
47+
fi
48+
49+
if [[ -f "$SERVICE_FILE" && "$(grep ExecStart "$SERVICE_FILE")" != *".venv/bin/jupyter"* ]]; then
50+
msg_info "Updating systemd service to use .venv"
51+
cat <<EOF >"$SERVICE_FILE"
52+
[Unit]
53+
Description=Jupyter Notebook Server
54+
After=network.target
55+
[Service]
56+
Type=simple
57+
WorkingDirectory=${INSTALL_DIR}
58+
ExecStart=${VENV_JUPYTER} notebook --ip=0.0.0.0 --port=8888 --allow-root
59+
Restart=always
60+
RestartSec=10
61+
[Install]
62+
WantedBy=multi-user.target
63+
EOF
64+
systemctl daemon-reexec
65+
systemctl restart jupyternotebook
66+
msg_ok "Service updated and restarted"
67+
fi
68+
69+
exit
3370
}
3471

3572
start
@@ -39,4 +76,4 @@ description
3976
msg_ok "Completed Successfully!\n"
4077
echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}"
4178
echo -e "${INFO}${YW} Access it using the following URL:${CL}"
42-
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8888${CL}"
79+
echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8888${CL}"

install/jupyternotebook-install.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,16 @@ setting_up_container
1313
network_check
1414
update_os
1515

16-
msg_info "Installing Dependencies"
17-
$STD apt-get install -y \
18-
python3 \
19-
python3-pip
20-
msg_ok "Installed Dependencies"
16+
PYTHON_VERSION="3.12" setup_uv
2117

22-
msg_info "Setting up Jupyter Notebook"
23-
$STD pip3 install jupyter
24-
msg_ok "Setup Jupyter Notebook"
18+
msg_info "Installing Jupyter"
19+
mkdir -p /opt/jupyter
20+
cd /opt/jupyter
21+
$STD uv venv /opt/jupyter/.venv
22+
$STD /opt/jupyter/.venv/bin/python -m ensurepip --upgrade
23+
$STD /opt/jupyter/.venv/bin/python -m pip install --upgrade pip
24+
$STD /opt/jupyter/.venv/bin/python -m pip install jupyter
25+
msg_ok "Installed Jupyter"
2526

2627
msg_info "Creating Service"
2728
cat <<EOF >/etc/systemd/system/jupyternotebook.service
@@ -31,14 +32,16 @@ After=network.target
3132
3233
[Service]
3334
Type=simple
34-
ExecStart=jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root
35+
WorkingDirectory=/opt/jupyter
36+
ExecStart=/opt/jupyter/.venv/bin/jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root
3537
Restart=always
3638
RestartSec=10
3739
3840
[Install]
3941
WantedBy=multi-user.target
4042
EOF
4143
systemctl enable -q --now jupyternotebook
44+
msg_ok "Created Service"
4245

4346
motd_ssh
4447
customize

0 commit comments

Comments
 (0)