From 92f631b6287aeed562f91677f2c4481bfd0e0a75 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Fri, 20 Jun 2025 11:28:17 +0200 Subject: [PATCH] migrate Jupyter Notebook to uv-based installation with update support (#5320) --- ct/jupyternotebook.sh | 57 ++++++++++++++++++++++++------ install/jupyternotebook-install.sh | 21 ++++++----- 2 files changed, 59 insertions(+), 19 deletions(-) diff --git a/ct/jupyternotebook.sh b/ct/jupyternotebook.sh index 2baf5baa8..2b6aef427 100644 --- a/ct/jupyternotebook.sh +++ b/ct/jupyternotebook.sh @@ -20,16 +20,53 @@ color catch_errors function update_script() { - header_info - check_container_storage - check_container_resources + header_info + check_container_storage + check_container_resources - msg_info "Updating ${APP} LXC" - $STD apt-get update - $STD apt-get install -y upgrade - $STD pip3 install jupyter --upgrade - msg_ok "Updated Successfully" - exit + INSTALL_DIR="/opt/jupyter" + VENV_PYTHON="${INSTALL_DIR}/.venv/bin/python" + VENV_JUPYTER="${INSTALL_DIR}/.venv/bin/jupyter" + SERVICE_FILE="/etc/systemd/system/jupyternotebook.service" + + if [[ ! -x "$VENV_JUPYTER" ]]; then + msg_info "Migrating to uv venv" + PYTHON_VERSION="3.12" setup_uv + mkdir -p "$INSTALL_DIR" + cd "$INSTALL_DIR" + $STD uv venv .venv + $STD "$VENV_PYTHON" -m ensurepip --upgrade + $STD "$VENV_PYTHON" -m pip install --upgrade pip + $STD "$VENV_PYTHON" -m pip install jupyter + msg_ok "Migrated to uv and installed Jupyter" + else + msg_info "Updating Jupyter" + $STD "$VENV_PYTHON" -m pip install --upgrade pip + $STD "$VENV_PYTHON" -m pip install --upgrade jupyter + msg_ok "Jupyter updated" + fi + + if [[ -f "$SERVICE_FILE" && "$(grep ExecStart "$SERVICE_FILE")" != *".venv/bin/jupyter"* ]]; then + msg_info "Updating systemd service to use .venv" + cat <"$SERVICE_FILE" +[Unit] +Description=Jupyter Notebook Server +After=network.target +[Service] +Type=simple +WorkingDirectory=${INSTALL_DIR} +ExecStart=${VENV_JUPYTER} notebook --ip=0.0.0.0 --port=8888 --allow-root +Restart=always +RestartSec=10 +[Install] +WantedBy=multi-user.target +EOF + systemctl daemon-reexec + systemctl restart jupyternotebook + msg_ok "Service updated and restarted" + fi + + exit } start @@ -39,4 +76,4 @@ description msg_ok "Completed Successfully!\n" echo -e "${CREATING}${GN}${APP} setup has been successfully initialized!${CL}" echo -e "${INFO}${YW} Access it using the following URL:${CL}" -echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8888${CL}" \ No newline at end of file +echo -e "${TAB}${GATEWAY}${BGN}http://${IP}:8888${CL}" diff --git a/install/jupyternotebook-install.sh b/install/jupyternotebook-install.sh index 843921187..4b8229d7c 100644 --- a/install/jupyternotebook-install.sh +++ b/install/jupyternotebook-install.sh @@ -13,15 +13,16 @@ setting_up_container network_check update_os -msg_info "Installing Dependencies" -$STD apt-get install -y \ - python3 \ - python3-pip -msg_ok "Installed Dependencies" +PYTHON_VERSION="3.12" setup_uv -msg_info "Setting up Jupyter Notebook" -$STD pip3 install jupyter -msg_ok "Setup Jupyter Notebook" +msg_info "Installing Jupyter" +mkdir -p /opt/jupyter +cd /opt/jupyter +$STD uv venv /opt/jupyter/.venv +$STD /opt/jupyter/.venv/bin/python -m ensurepip --upgrade +$STD /opt/jupyter/.venv/bin/python -m pip install --upgrade pip +$STD /opt/jupyter/.venv/bin/python -m pip install jupyter +msg_ok "Installed Jupyter" msg_info "Creating Service" cat </etc/systemd/system/jupyternotebook.service @@ -31,7 +32,8 @@ After=network.target [Service] Type=simple -ExecStart=jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root +WorkingDirectory=/opt/jupyter +ExecStart=/opt/jupyter/.venv/bin/jupyter notebook --ip=0.0.0.0 --port=8888 --allow-root Restart=always RestartSec=10 @@ -39,6 +41,7 @@ RestartSec=10 WantedBy=multi-user.target EOF systemctl enable -q --now jupyternotebook +msg_ok "Created Service" motd_ssh customize