feat: one-click deploy.sh (system deps + venv + DB + systemd)

scripts/deploy.sh covers the full path from fresh OS to running service:
  1. install system packages (apt/yum/dnf auto-detect, includes bind/python3/venv/git)
  2. create Python venv + pip install -r requirements.txt (avoids PEP 668)
  3. init SQLite DB (default admin/admin)
  4. delegate BIND config to setup-bind.sh (or --skip-bind)
  5. install + enable systemd unit dns-web (gunicorn, port 5300)
  6. restart + verify (port listen + HTTP 302)

Idempotent; supports --dry-run, --skip-bind, --port, DNS_WEB_PORT/USER/WORKERS.
Type=exec (not Type=notify) because gunicorn 21.x has no sd_notify.
README updated with deploy.sh as recommended path; .gitignore adds venv/.
This commit is contained in:
Your Name
2026-08-07 11:19:01 +08:00
parent fb3f13c3b2
commit e20e235a1e
3 changed files with 320 additions and 1 deletions
+45 -1
View File
@@ -81,7 +81,51 @@ dns-service/
## 安装部署
### 1. 安装 BIND9
### 方式一:一键部署(推荐)
`scripts/deploy.sh` 从干净系统一路到运行中的服务,自动完成:
1. 安装系统包(bind9 / bind-utils / python3 / pip / venv / git,自动识别 apt/yum/dnf
2. 创建 Python 虚拟环境 `venv/`,安装 `requirements.txt`(用 venv 的 pip,避开 Debian 12+ PEP 668
3. 初始化 SQLite 数据库(默认 `admin/admin`
4. 调用 `scripts/setup-bind.sh` 配置 BINDzone 目录、named.conf.local include、权限)
5. 安装并启用 systemd 服务 `dns-web`gunicorn,端口 53002 workers
6. 启动服务并验证端口 + HTTP 响应
```bash
git clone ssh://git@git.cnbugs.com:10022/AI-Agent/dns-service.git
cd dns-service
# 先预览会做什么(推荐):
sudo bash scripts/deploy.sh --dry-run
# 确认后真跑:
sudo bash scripts/deploy.sh
# 如果 BIND 已经配好了只想更新应用:
sudo bash scripts/deploy.sh --skip-bind
# 换端口:
sudo bash scripts/deploy.sh --port 5301
# 或用环境变量:
sudo DNS_WEB_PORT=5301 DNS_WEB_WORKERS=4 bash scripts/deploy.sh
```
脚本幂等,可重复执行。升级代码后重跑一次即可(venv 和 DB 保留,只补缺失部分)。
**可调环境变量:**
| 变量 | 默认 | 说明 |
|------|------|------|
| `DNS_WEB_PORT` | `5300` | 监听端口 |
| `DNS_WEB_USER` | `root` | 服务运行用户(需能操作 BIND 配置 + systemctl |
| `DNS_WEB_WORKERS` | `2` | gunicorn worker 数 |
> **关于 root 用户**Web 应用需要 root 权限来操作 `/etc/bind/*` 配置文件和执行 `systemctl`/`rndc` 命令。如果你的环境不允许 root 跑服务,用 `DNS_WEB_USER=<user>` 覆盖,并给该用户配 sudo 规则。systemd unit 用 `Type=exec`gunicorn 21.x 不带 sd_notify,用 `Type=notify` 会卡 90 秒超时然后失败)。
### 方式二:手动部署
适合需要完全控制每一步的场景。
```bash
apt-get update