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
+33 -12
View File
@@ -6,11 +6,18 @@
# then starts the service and verifies /healthz.
#
# Usage:
# scripts/deploy_autodl.sh [--token <TOKEN>] [--port <PORT>] [--config <cfg>]
# --token auth token; sets the X-Genarrative-Image-Token requirement.
# Omit to run OPEN (no auth) -- a warning is printed.
# --port public-mapped container port (default 6006).
# --config pipeline config (default configs/gpu.yaml).
# scripts/deploy_autodl.sh [--token <TOKEN>] [--open] [--port <PORT>]
# [--config <cfg>] [--log-dir <dir>]
# --token auth token; sets/updates the X-Genarrative-Image-Token
# requirement. Omitting it REUSES an existing token (a re-run to
# tweak another knob won't drop auth); only a first run with no
# token starts OPEN.
# --open explicitly remove the token and run OPEN (no auth).
# --port public-mapped container port (default 6006).
# --config pipeline config (default configs/gpu.yaml).
# --log-dir directory for bgfilter.log (default ~/autodl-tmp, the AutoDL
# persistent data disk; unlike /tmp it survives container resets).
# File is <dir>/bgfilter.log.
#
# Assumes: the repo is already checked out (this script does NOT git pull), root
# user, torch/CUDA provided by the AutoDL image, python at /root/miniconda3.
@@ -25,13 +32,17 @@ set -euo pipefail
# ---- args ----
TOKEN=""
OPEN=0
PORT=6006
CONFIG="configs/gpu.yaml"
LOG_DIR="$HOME/autodl-tmp"
while [ $# -gt 0 ]; do
case "$1" in
--token) TOKEN="${2:-}"; shift 2;;
--port) PORT="${2:-}"; shift 2;;
--config) CONFIG="${2:-}"; shift 2;;
--token) TOKEN="${2:-}"; shift 2;;
--open) OPEN=1; shift;;
--port) PORT="${2:-}"; shift 2;;
--config) CONFIG="${2:-}"; shift 2;;
--log-dir) LOG_DIR="${2:-}"; shift 2;;
-h|--help) sed -n '2,30p' "$0" | sed 's/^# \?//'; exit 0;;
*) echo "unknown arg: $1" >&2; exit 1;;
esac
@@ -48,9 +59,12 @@ TOKEN_FILE="$HOME/.bgfilter_token"
RUN_WRAPPER="$HOME/bgfilter_run.sh"
SUP_CONF="$HOME/supervisord.conf"
SUP_SOCK="$HOME/bgfilter-supervisor.sock"
LOG=/tmp/bgfilter.log
# Service log: persistent by default ($HOME survives, /tmp does not on AutoDL).
# Override the directory with --log-dir; the file is always <dir>/bgfilter.log.
mkdir -p "$LOG_DIR"
LOG="$LOG_DIR/bgfilter.log"
echo "[deploy] app_dir=$APP_DIR python=$PY port=$PORT config=$CONFIG"
echo "[deploy] app_dir=$APP_DIR python=$PY port=$PORT config=$CONFIG log=$LOG"
# ---- 1. detect CUDA -> pick the matching cupy wheel (GPU foreground) ----
CUDA_VER="$("$PY" -c 'import torch;print(torch.version.cuda or "")' 2>/dev/null || echo "")"
@@ -78,12 +92,19 @@ echo "[deploy] fetching weights..."
( cd "$APP_DIR" && "$PY" scripts/fetch_weights.py )
# ---- 4. auth token ----
# --token sets/updates the token; --open explicitly removes it (service OPEN).
# With neither, an existing token is REUSED (so re-running to tweak an unrelated
# knob never silently drops auth); only a first run with no token starts OPEN.
if [ -n "$TOKEN" ]; then
printf '%s' "$TOKEN" > "$TOKEN_FILE"; chmod 600 "$TOKEN_FILE"
echo "[deploy] auth ENABLED (token -> $TOKEN_FILE, chmod 600)"
else
elif [ "$OPEN" = 1 ]; then
rm -f "$TOKEN_FILE"
echo "[deploy] WARN: no --token -> service is OPEN (no auth)"
echo "[deploy] auth DISABLED via --open (service is OPEN, no auth)"
elif [ -f "$TOKEN_FILE" ]; then
echo "[deploy] reusing existing token ($TOKEN_FILE); pass --open to disable auth"
else
echo "[deploy] WARN: no token -> service is OPEN (no auth); pass --token to enable"
fi
# ---- 5. launch wrapper (exec so supervisord tracks the uvicorn PID) ----