migrate Jupyter Notebook to uv-based installation with update support (#5320)
This commit is contained in:
parent
9133782289
commit
92f631b628
@ -24,11 +24,48 @@ function update_script() {
|
|||||||
check_container_storage
|
check_container_storage
|
||||||
check_container_resources
|
check_container_resources
|
||||||
|
|
||||||
msg_info "Updating ${APP} LXC"
|
INSTALL_DIR="/opt/jupyter"
|
||||||
$STD apt-get update
|
VENV_PYTHON="${INSTALL_DIR}/.venv/bin/python"
|
||||||
$STD apt-get install -y upgrade
|
VENV_JUPYTER="${INSTALL_DIR}/.venv/bin/jupyter"
|
||||||
$STD pip3 install jupyter --upgrade
|
SERVICE_FILE="/etc/systemd/system/jupyternotebook.service"
|
||||||
msg_ok "Updated Successfully"
|
|
||||||
|
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
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,15 +13,16 @@ setting_up_container
|
|||||||
network_check
|
network_check
|
||||||
update_os
|
update_os
|
||||||
|
|
||||||
msg_info "Installing Dependencies"
|
PYTHON_VERSION="3.12" setup_uv
|
||||||
$STD apt-get install -y \
|
|
||||||
python3 \
|
|
||||||
python3-pip
|
|
||||||
msg_ok "Installed Dependencies"
|
|
||||||
|
|
||||||
msg_info "Setting up Jupyter Notebook"
|
msg_info "Installing Jupyter"
|
||||||
$STD pip3 install jupyter
|
mkdir -p /opt/jupyter
|
||||||
msg_ok "Setup Jupyter Notebook"
|
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"
|
msg_info "Creating Service"
|
||||||
cat <<EOF >/etc/systemd/system/jupyternotebook.service
|
cat <<EOF >/etc/systemd/system/jupyternotebook.service
|
||||||
@ -31,7 +32,8 @@ After=network.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
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
|
Restart=always
|
||||||
RestartSec=10
|
RestartSec=10
|
||||||
|
|
||||||
@ -39,6 +41,7 @@ RestartSec=10
|
|||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
EOF
|
EOF
|
||||||
systemctl enable -q --now jupyternotebook
|
systemctl enable -q --now jupyternotebook
|
||||||
|
msg_ok "Created Service"
|
||||||
|
|
||||||
motd_ssh
|
motd_ssh
|
||||||
customize
|
customize
|
||||||
|
Loading…
x
Reference in New Issue
Block a user