feat: 新增 systemd 持久化部署(deploy/ztools2.service + install-systemd.sh)

systemd 管理 zTools2 后端实现开机自启 + 崩溃自动重启:
- deploy/ztools2.service 模板(Restart=on-failure,after mysql)
- deploy/install-systemd.sh 自动检测 .venv 或系统 uvicorn,填充路径安装
- README 补持久化部署章节
This commit is contained in:
2026-07-27 13:52:23 +08:00
parent aa08a1cf60
commit 29c5462734
3 changed files with 94 additions and 0 deletions

View File

@@ -184,3 +184,18 @@ systemctl reload apache2
- **重新生成 DB 密码**`.venv/bin/python -m app.scripts.init_db`(保留现有:`KEEP_DB_PASSWORD=1`)。
- **多 worker 限制**:记事本 hub 是进程内存,多 uvicorn worker 下不互通,保持 `workers: 1`
- **数据库表**ORM 启动时自动建表(`init_db_schema``sql/schema.sql` 供参考/手动初始化。
## 持久化部署systemd
`./start.sh` 适合手动运维;生产推荐用 systemd 管理实现开机自启 + 崩溃自动重启:
```bash
./deploy/install-systemd.sh # 安装并启动 ztools2 服务(开机自启)
systemctl status ztools2 # 状态
journalctl -u ztools2 -f # 日志
sudo systemctl restart ztools2 # 重启(更新代码后)
```
脚本自动检测 `.venv/bin/uvicorn` 或系统 `uvicorn`,用实际路径填充 `deploy/ztools2.service` 模板。卸载:`systemctl disable --now ztools2 && rm /etc/systemd/system/ztools2.service && systemctl daemon-reload`
> 与 zMainPage 整体部署配合systemd 管后端,`zMainPage/deploy.sh --no-restart` 部署前端。详见 zMainPage 的 [`docs/deployment.md`](https://git.zikai.wang/zikai/zMainPage/src/branch/main/docs/deployment.md)。