@@ -20,16 +20,53 @@ color
2020catch_errors
2121
2222function 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
3572start
@@ -39,4 +76,4 @@ description
3976msg_ok " Completed Successfully!\n"
4077echo -e " ${CREATING}${GN}${APP} setup has been successfully initialized!${CL} "
4178echo -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} "
0 commit comments