Systemd 服务创建指南
来源:
sources/创建守护进程.18928792.md
创建服务文件
以 JupyterLab 为例:
sudo tee /etc/systemd/system/jupyter-lab.service <<EOF
[Unit]
Description=JupyterLab
After=network.target
[Service]
Type=simple
PIDFile=/run/jupyter.pid
ExecStart=/home/username/anaconda3/bin/jupyter lab \
--config=/home/username/.jupyter/jupyter_lab_config.py \
--no-browser
User=username
Group=username
WorkingDirectory=/home/username
Restart=always
RestartSec=10
Environment="PATH=/home/username/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
[Install]
WantedBy=multi-user.target
EOF
管理命令
# 重载配置
sudo systemctl daemon-reload
# 启动并设置开机自启
sudo systemctl start jupyter-lab
sudo systemctl enable jupyter-lab
# 查看状态
sudo systemctl status jupyter-lab
# 编辑守护进程
sudo systemctl edit ollama
关键字段说明
| 字段 | 说明 |
|---|---|
Type=simple |
简单服务类型 |
ExecStart |
启动命令 |
Restart=always |
总是重启 |
RestartSec=10 |
重启间隔 10 秒 |
WantedBy=multi-user.target |
多用户模式启动 |
相关页面
- Django_Server_Deploy - Django 服务器部署
- PM2_Use - PM2 进程管理器
最后更新: 2026-04-30