dy-dashboard/vault/知识库/工作指南/训练记录/2026-06-26-配置生产环境systemd服务.md
2026-10-28 11:14:17 +08:00

28 lines
903 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 2026-06-26 生产环境配置systemd服务
## 背景
新电脑(生产环境)重启后,数据平台(Gunicorn :18888)不会自动启动,需要手动执行命令启动,不利于生产环境稳定性。
旧电脑已有 `dy-dashboard.service` 用户级 systemd 服务实现开机自启。
## 操作
在新电脑上创建并启用用户级 systemd 服务:
1. 创建 `~/.config/systemd/user/dy-dashboard.service`
2. 配置 Gunicorn 执行路径为 `venv/bin/gunicorn`
3. 设置 `Restart=always` 保证崩溃自动重启
4. 设置 `After=mysql.service` + `Wants=mysql.service` 确保 MySQL 就绪后再启动
5. `systemctl --user enable` 启用开机自启
6. `systemctl --user restart` 启动服务
## 涉及文件
- `/home/dieya/.config/systemd/user/dy-dashboard.service`
## 验证
`systemctl --user status dy-dashboard.service --no-pager`
- Active: active (running)
- Enabled: yes