migrate Jupyter Notebook to uv-based installation with update support (#5320)
This commit is contained in:
parent
9133782289
commit
92f631b628
@ -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 <<EOF >"$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
|
||||
|
@ -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 <<EOF >/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
|
||||
|
Loading…
x
Reference in New Issue
Block a user