zcbot/deploy/sandbox/probe_mermaid.sh

30 lines
2.0 KiB
Bash
Raw Permalink 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.

#!/usr/bin/env bash
# 在 sandbox 容器里实测 mmdc/chromium区分「chromium 缺包」vs「纯启动超时(/dev/shm 64MB)」。
# 用法(服务器上,任选其一):
# A) 进一个活着的 per-user 容器(最贴真,复用线上 64MB /dev/shm 默认):
# C=$(docker ps --filter "label=zcbot.product=sandbox" --format '{{.Names}}' | head -1)
# docker cp deploy/sandbox/probe_mermaid.sh "$C":/tmp/probe.sh
# docker exec "$C" bash /tmp/probe.sh
# B) 没有活容器时,起一个临时的(显式 NOT 传 --shm-size,复现线上 64MB):
# docker run --rm --read-only --tmpfs /tmp:exec,size=512m,mode=1777 \
# --cap-drop=ALL --security-opt=no-new-privileges \
# --entrypoint bash zcbot-sandbox:latest /dev/stdin < deploy/sandbox/probe_mermaid.sh
set -u
echo "===== /dev/shm size (期望线上 64M) ====="; df -h /dev/shm
echo "===== chromium 是否在 (缺包则这里就失败) ====="
command -v chromium && chromium --version 2>&1 | head -1 || echo "[FAIL] chromium 缺包/不可执行"
cd /tmp; printf 'flowchart TB\n A[甲]-->B[乙]\n' > d.mmd
echo; echo "===== A: 模型自造 config(漏 --disable-dev-shm-usage)→ 预期挂起/超时 ====="
printf '{"args":["--no-sandbox","--disable-setuid-sandbox"]}' > bad.json
ts=$SECONDS; timeout 60 mmdc -i d.mmd -o a.png -p bad.json >a.log 2>&1; rc=$?
echo "rc=$rc 用时=$((SECONDS-ts))s"; tail -3 a.log; ls -l a.png 2>/dev/null && echo "[A 出图]" || echo "[A 无图]"
echo; echo "===== B: 镜像备好的 /sandbox/puppeteer-config.json(含 --disable-dev-shm-usage)→ 预期成功 ====="
ts=$SECONDS; timeout 60 mmdc -i d.mmd -o b.png -p /sandbox/puppeteer-config.json >b.log 2>&1; rc=$?
echo "rc=$rc 用时=$((SECONDS-ts))s"; tail -3 b.log; ls -l b.png 2>/dev/null && echo "[B 出图]" || echo "[B 无图]"
echo; echo "===== 结论 ====="
echo "chromium 在 + A挂超时 + B出图 => 纯 /dev/shm 64MB 问题,fix=给 docker run 加 --shm-size 或强制用 B 的 config"
echo "chromium 缺/B 也失败 => 更深的环境问题,看上面 b.log"