如何将 Jupyter Lab 作为 systemd 服务运行

本指南解释如何在 Linux 上将 Jupyter Lab 作为 systemd 服务运行。下面你找到 systemd 单元文件和一个简单的启动脚本。

创建包含以下内容的 systemd 服务文件 /etc/systemd/system/jupyter-lab.service

jupyter-lab.service
[Unit]
Description=Jupyter Lab
After=network.target

[Service]
Type=simple
User=uli
WorkingDirectory=/home/uli
ExecStart=/usr/local/bin/jupyter-lab --no-browser --ip=0.0.0.0
Restart=on-failure

[Install]
WantedBy=multi-user.target

/usr/local/bin/jupyter-lab-start.sh 中创建一个小启动脚本:

jupyter-lab-start.sh
#!/bin/bash
source /home/uli/.venv/bin/activate
exec jupyter-lab --no-browser --ip=0.0.0.0

启用并启动服务:

enable_jupyter_service.sh
sudo systemctl daemon-reload
sudo systemctl enable --now jupyter-lab.service
sudo systemctl status jupyter-lab.service

如果遇到路径问题,检查单元文件中 systemd 使用的 ExecStart 并确保路径是绝对的。


Check out similar posts by category: DevOps