Document AutoDL deploy path; harden its token/log handling

Add a section 0 to DEPLOY.md/DEPLOY_ZH.md covering the AutoDL one-click
path (supervisord, not systemd), which was previously only self-documented
in scripts/deploy_autodl.sh.

deploy_autodl.sh:
- --log-dir (default ~/autodl-tmp, the persistent data disk) so the service
  log no longer lands in /tmp, which AutoDL wipes on container reset.
- Re-running without --token now REUSES an existing token instead of
  deleting it, so tweaking an unrelated knob can't silently disable auth;
  add --open to explicitly run without auth.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 04:19:10 +00:00
parent dc4badd0e0
commit 755e5fda44
3 changed files with 139 additions and 12 deletions
+49
View File
@@ -7,6 +7,55 @@
服务入口是 `app.py`(`uvicorn app:app`)。API 契约和算法细节见 [README.md](README.md)。
下面第 1–12 节是**手动 CPU 部署**(systemd + nginx,推荐默认)。如果你部署在
**AutoDL GPU 盒子**上,走第 0 节的一键脚本更快;两者是各自独立的部署路线。
---
## 0. 快速路径:AutoDL 一键部署(GPU)
在 AutoDL GPU 实例上,用仓库自带的一键脚本部署,无需手动装依赖 / 配 systemd:
```bash
# 假设仓库已 checkout 到实例(脚本不会 git pull),使用 server-edition 分支
cd /root/BGfilter-server # 你的实际路径
scripts/deploy_autodl.sh --token <TOKEN>
```
脚本**幂等**地完成:装依赖 + 拉模型权重 + 按 CUDA 版本装对应 CuPy(GPU 前景合成)
+ 起一个 **supervisord** 实例(崩溃自动重启)+ 往 `~/.bashrc` 写交互登录自启,
最后启动服务并校验 `/healthz`。
参数:
| 参数 | 默认 | 说明 |
| --- | --- | --- |
| `--token <TOKEN>` | 无 | 鉴权 token,设置/更新后 `/remove-background` 要求 header `X-Genarrative-Image-Token`。**省略则沿用已有 token**(重跑改别的参数不会误关鉴权);只有首次无 token 才开放。 |
| `--open` | — | 显式删除 token、以开放模式运行(无鉴权)。 |
| `--port <PORT>` | `6006` | 容器内监听端口(对应 AutoDL 的公网映射端口)。 |
| `--config <cfg>` | `configs/gpu.yaml` | 流水线配置。 |
| `--log-dir <dir>` | `~/autodl-tmp` | 服务日志 `bgfilter.log` 所在目录。默认落在 AutoDL 持久数据盘 `~/autodl-tmp`(容器重置不丢),而非 `/tmp`。 |
**前提**:仓库已 checkout(脚本不 `git pull`)、root 用户、torch/CUDA 由 AutoDL 镜像提供、
python 在 `/root/miniconda3`。
**两个 AutoDL 固有的坑**(脚本管不了):
- **公网 URL 映射**(如 `6006 → https://...:8443`)要在 **AutoDL 网页控制台**里设,脚本不负责。
- **容器重启后**服务不会自动起来——AutoDL 没有 systemd / 开机钩子,自启写在 `~/.bashrc` 里,
需要**开一个交互式 shell(SSH / JupyterLab 终端)** 才会触发拉起。
与 supervisord 打交道(socket 在 `~/bgfilter-supervisor.sock`,配置在 `~/supervisord.conf`):
```bash
/root/miniconda3/bin/supervisorctl -c ~/supervisord.conf status bgfilter # 状态
/root/miniconda3/bin/supervisorctl -c ~/supervisord.conf restart bgfilter # 重启
tail -f ~/autodl-tmp/bgfilter.log # 日志(默认 ~/autodl-tmp)
```
> 改了 `configs/*.yaml`(比如开 `cross_check.reuse_as_seg`)后,用上面的 `restart bgfilter`
> 让服务重新加载配置——配置只在启动时读入,没有请求级开关。
---
## 1. 前置条件