chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
# 双插件 VM 部署脚本。
|
|
|
|
|
|
#
|
|
|
|
|
|
# 把错题本里逐条踩出来的部署纪律固化成步骤,避免每次部署重新暴露同一批历史问题:
|
|
|
|
|
|
# - 回滚副本留在插件扫描目录里 → AstrBot 当成插件去导入,启动日志出 ERRO
|
|
|
|
|
|
# - 属主/权限不对(0700)→ 服务读不到 main.py
|
|
|
|
|
|
# - 旧 pycache 权限 → compileall 误报
|
|
|
|
|
|
# - 先部署陪伴后部署记忆 → 陪伴启动时对端不在,桥探测落进负缓存
|
|
|
|
|
|
# - 备份指针不更新 → 回滚会把之后的真机修复一并抹掉
|
|
|
|
|
|
#
|
|
|
|
|
|
# 用法:
|
|
|
|
|
|
# ops/deploy-plugin.sh <memory|companion|both> [文件...]
|
|
|
|
|
|
# 不给文件 = 整目录替换;给文件 = 只替换这些文件(相对插件根目录)
|
|
|
|
|
|
# 环境变量 VM 指定目标主机,默认 astrbot-vm(需已配置 ssh 免密)
|
|
|
|
|
|
#
|
|
|
|
|
|
# 示例:
|
|
|
|
|
|
# ops/deploy-plugin.sh companion daily_state.py planning.py
|
|
|
|
|
|
# ops/deploy-plugin.sh both
|
|
|
|
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
|
|
|
|
VM="${VM:-astrbot-vm}"
|
2026-07-27 13:03:21 +08:00
|
|
|
|
SSH_KEY="${SSH_KEY:-}"
|
|
|
|
|
|
SSH_PORT="${SSH_PORT:-22}"
|
|
|
|
|
|
PYTHON_BIN="${PYTHON_BIN:-python}"
|
|
|
|
|
|
SKIP_LOCAL_TESTS="${SKIP_LOCAL_TESTS:-0}"
|
2026-07-27 13:14:23 +08:00
|
|
|
|
DETAIL_ENHANCEMENT_ENABLED="${DETAIL_ENHANCEMENT_ENABLED:-}"
|
2026-07-27 13:03:21 +08:00
|
|
|
|
SSH_OPTS=(-o BatchMode=yes -p "$SSH_PORT")
|
|
|
|
|
|
SCP_OPTS=(-o BatchMode=yes -P "$SSH_PORT")
|
|
|
|
|
|
if [ -n "$SSH_KEY" ]; then
|
|
|
|
|
|
[ -f "$SSH_KEY" ] || { echo "错误: SSH_KEY 不存在: $SSH_KEY" >&2; exit 1; }
|
|
|
|
|
|
SSH_OPTS+=(-i "$SSH_KEY" -o IdentitiesOnly=yes)
|
|
|
|
|
|
SCP_OPTS+=(-i "$SSH_KEY" -o IdentitiesOnly=yes)
|
|
|
|
|
|
fi
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
TARGET="${1:-}"
|
|
|
|
|
|
shift || true
|
|
|
|
|
|
FILES=("$@")
|
|
|
|
|
|
|
|
|
|
|
|
# 本脚本随陪伴插件仓库走;两个插件仓库是项目根目录下的同级目录
|
|
|
|
|
|
COMPANION_SRC="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
|
|
|
|
PROJECT_ROOT="$(cd "$COMPANION_SRC/.." && pwd)"
|
|
|
|
|
|
MEMORY_SRC="$PROJECT_ROOT/astrbot_plugin_memory_companion-main"
|
|
|
|
|
|
if [ ! -d "$MEMORY_SRC" ]; then
|
|
|
|
|
|
echo "错误: 找不到记忆插件仓库 $MEMORY_SRC(两个仓库应是项目根下的同级目录)" >&2
|
|
|
|
|
|
exit 1
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
PLUGIN_DIR=/var/lib/astrbot/data/plugins
|
|
|
|
|
|
BACKUP_ROOT=/var/lib/astrbot/ops-replace-backups
|
|
|
|
|
|
PY=/var/lib/astrbot/.local/share/uv/tools/astrbot/bin/python
|
|
|
|
|
|
# 服务以 astrbot 身份运行(systemd User=astrbot),所以属主必须是 astrbot:astrbot。
|
|
|
|
|
|
# 错题本早期写过 root:root,那是错的——按实机与 systemd 配置为准。
|
|
|
|
|
|
OWNER=astrbot:astrbot
|
|
|
|
|
|
STAMP="$(date +%Y%m%d-%H%M%S)"
|
|
|
|
|
|
|
|
|
|
|
|
die() { echo "错误: $*" >&2; exit 1; }
|
|
|
|
|
|
|
|
|
|
|
|
case "$TARGET" in
|
|
|
|
|
|
memory|companion|both) ;;
|
|
|
|
|
|
*) die "用法: $0 <memory|companion|both> [文件...]" ;;
|
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$TARGET" = both ] && [ ${#FILES[@]} -gt 0 ]; then
|
|
|
|
|
|
die "both 模式不接受文件列表:两个插件的文件名会混在一起"
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo "==> 目标主机 $VM 备份时间戳 $STAMP"
|
|
|
|
|
|
|
2026-07-27 13:03:21 +08:00
|
|
|
|
# ---------- 1. Local gate: keep failing code off the VM ----------
|
|
|
|
|
|
if [ "$SKIP_LOCAL_TESTS" = "1" ]; then
|
|
|
|
|
|
echo "==> Skipping local tests (SKIP_LOCAL_TESTS=1)"
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "==> Local tests via $PYTHON_BIN"
|
|
|
|
|
|
if [ "$TARGET" = companion ] || [ "$TARGET" = both ]; then
|
|
|
|
|
|
(cd "$COMPANION_SRC" && "$PYTHON_BIN" -m unittest discover -s tests -q) || die "companion tests failed"
|
|
|
|
|
|
fi
|
|
|
|
|
|
if [ "$TARGET" = memory ] || [ "$TARGET" = both ]; then
|
|
|
|
|
|
(cd "$MEMORY_SRC" && "$PYTHON_BIN" -m unittest discover -s tests -q) || die "memory tests failed"
|
|
|
|
|
|
fi
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- 2. 远端备份,并把回滚指针指向这次 ----------
|
|
|
|
|
|
BACKUP="$BACKUP_ROOT/deploy-$STAMP"
|
|
|
|
|
|
echo "==> 远端备份 $BACKUP"
|
2026-07-27 13:03:21 +08:00
|
|
|
|
ssh "${SSH_OPTS[@]}" "$VM" "sudo mkdir -p '$BACKUP'
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
for name in astrbot_plugin_memory_companion_ops astrbot_plugin_private_companion_ops; do
|
|
|
|
|
|
sudo tar czf '$BACKUP'/plugin-\$name.tar.gz -C '$PLUGIN_DIR' \$name
|
|
|
|
|
|
sudo cp -r '$PLUGIN_DIR'/\$name '$BACKUP'/before-\$name
|
|
|
|
|
|
done
|
|
|
|
|
|
sudo cp /var/lib/astrbot/data/config/astrbot_plugin_*_ops_config.json '$BACKUP'/ 2>/dev/null || true
|
|
|
|
|
|
# 回滚副本一律落在备份区,绝不留在插件扫描目录里
|
|
|
|
|
|
echo '$BACKUP' | sudo tee '$BACKUP_ROOT/LATEST_M6' >/dev/null"
|
|
|
|
|
|
|
|
|
|
|
|
push_one() {
|
|
|
|
|
|
local src="$1" name="$2"
|
|
|
|
|
|
local dest="$PLUGIN_DIR/$name"
|
|
|
|
|
|
if [ ${#FILES[@]} -eq 0 ]; then
|
|
|
|
|
|
echo "==> 整目录替换 $name"
|
|
|
|
|
|
tar czf - -C "$src" --exclude=__pycache__ --exclude=.git --exclude=.tmp . \
|
2026-07-27 13:03:21 +08:00
|
|
|
|
| ssh "${SSH_OPTS[@]}" "$VM" "cat > /tmp/$name.tar.gz"
|
|
|
|
|
|
ssh "${SSH_OPTS[@]}" "$VM" "sudo rm -rf '$dest' && sudo mkdir -p '$dest' \
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
&& sudo tar xzf /tmp/$name.tar.gz -C '$dest' && rm -f /tmp/$name.tar.gz"
|
|
|
|
|
|
else
|
|
|
|
|
|
echo "==> 增量替换 $name: ${FILES[*]}"
|
|
|
|
|
|
for f in "${FILES[@]}"; do
|
|
|
|
|
|
[ -f "$src/$f" ] || die "本地不存在: $src/$f"
|
2026-07-27 13:03:21 +08:00
|
|
|
|
scp -q "${SCP_OPTS[@]}" "$src/$f" "$VM:/tmp/$(basename "$f")"
|
|
|
|
|
|
ssh "${SSH_OPTS[@]}" "$VM" "sudo mkdir -p \"\$(dirname '$dest/$f')\" \
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
&& sudo cp '/tmp/$(basename "$f")' '$dest/$f' && rm -f '/tmp/$(basename "$f")'"
|
|
|
|
|
|
done
|
|
|
|
|
|
fi
|
2026-07-27 13:03:21 +08:00
|
|
|
|
ssh "${SSH_OPTS[@]}" "$VM" "sudo chown -R $OWNER '$dest'
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
sudo find '$dest' -type d -exec chmod 755 {} +
|
|
|
|
|
|
sudo find '$dest' -type f -exec chmod 644 {} +
|
|
|
|
|
|
# 扫描目录里不允许留任何非插件目录(.old/.new/.bak 会被当成插件导入)
|
|
|
|
|
|
leftovers=\$(sudo find '$PLUGIN_DIR' -maxdepth 1 -name '*.old' -o -maxdepth 1 -name '*.new' -o -maxdepth 1 -name '*.bak' | head)
|
|
|
|
|
|
if [ -n \"\$leftovers\" ]; then echo \"错误: 插件扫描目录残留 \$leftovers\" >&2; exit 1; fi
|
|
|
|
|
|
# PYTHONPYCACHEPREFIX 避开旧 pycache 的权限问题
|
|
|
|
|
|
sudo -u astrbot env PYTHONPYCACHEPREFIX=/tmp/pycache-deploy '$PY' -m compileall -q '$dest' >/dev/null \
|
|
|
|
|
|
|| { echo '错误: 远端 compileall 未通过' >&2; exit 1; }"
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- 3. 停服 → 记忆先于陪伴 → 启动 ----------
|
|
|
|
|
|
echo "==> 停服"
|
2026-07-27 13:03:21 +08:00
|
|
|
|
ssh "${SSH_OPTS[@]}" "$VM" "sudo systemctl stop astrbot"
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
|
|
|
|
|
|
# 顺序有讲究:陪伴启动时会探测记忆插件的桥,对端不在会落进负缓存
|
|
|
|
|
|
if [ "$TARGET" = memory ] || [ "$TARGET" = both ]; then
|
|
|
|
|
|
push_one "$MEMORY_SRC" astrbot_plugin_memory_companion_ops
|
|
|
|
|
|
fi
|
|
|
|
|
|
if [ "$TARGET" = companion ] || [ "$TARGET" = both ]; then
|
|
|
|
|
|
push_one "$COMPANION_SRC" astrbot_plugin_private_companion_ops
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
echo "==> 启动"
|
2026-07-27 13:14:23 +08:00
|
|
|
|
# Apply explicit plugin configuration only after AstrBot has stopped: otherwise
|
|
|
|
|
|
# its shutdown persistence can overwrite the staged value with stale memory.
|
|
|
|
|
|
if [ -n "$DETAIL_ENHANCEMENT_ENABLED" ] && { [ "$TARGET" = companion ] || [ "$TARGET" = both ]; }; then
|
|
|
|
|
|
echo "==> Applying DETAIL_ENHANCEMENT_ENABLED=$DETAIL_ENHANCEMENT_ENABLED"
|
|
|
|
|
|
cat <<'PY' | ssh "${SSH_OPTS[@]}" "$VM" "sudo '$PY' - '$DETAIL_ENHANCEMENT_ENABLED'"
|
|
|
|
|
|
import codecs
|
|
|
|
|
|
import json
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
path = "/var/lib/astrbot/data/config/astrbot_plugin_private_companion_ops_config.json"
|
|
|
|
|
|
value = sys.argv[1].strip().lower() in ("1", "true", "yes", "on")
|
|
|
|
|
|
with codecs.open(path, "r", "utf-8-sig") as handle:
|
|
|
|
|
|
config = json.load(handle)
|
|
|
|
|
|
config["enable_detail_enhancement"] = value
|
|
|
|
|
|
with codecs.open(path, "w", "utf-8-sig") as handle:
|
|
|
|
|
|
json.dump(config, handle, ensure_ascii=False, indent=2)
|
|
|
|
|
|
handle.write("\n")
|
|
|
|
|
|
print("enable_detail_enhancement=" + str(value))
|
|
|
|
|
|
PY
|
|
|
|
|
|
fi
|
2026-07-27 13:03:21 +08:00
|
|
|
|
ssh "${SSH_OPTS[@]}" "$VM" "sudo systemctl start astrbot"
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
sleep 60
|
|
|
|
|
|
|
|
|
|
|
|
# ---------- 4. 验证 ----------
|
|
|
|
|
|
echo "==> 验证"
|
2026-07-27 13:03:21 +08:00
|
|
|
|
ssh "${SSH_OPTS[@]}" "$VM" '
|
chore: script the deployment discipline
There was no shell script anywhere in either repo, so every deployment was
typed by hand and every deployment re-exposed the same pitfalls: rollback
copies left in the plugin scan directory, wrong ownership, stale pycache,
deploying the companion before memory, and a rollback pointer left aimed at an
older backup.
ops/deploy-plugin.sh fixes the order: local test gate, remote backup with the
LATEST_M6 pointer updated, stop, memory before companion (the companion probes
the memory bridge at startup and caches a negative result if the peer is
absent), ownership and modes, a scan-directory residue check that exits
non-zero on any .old/.new/.bak, remote compileall with PYTHONPYCACHEPREFIX,
start, then verification of service state and plugin-level error count.
The ownership rule was documented two ways -- root:root in the errata,
astrbot:astrbot in the M6.1.8 record. The service runs as User=astrbot, so
astrbot:astrbot is correct and the script now says so in a comment.
Also noted, in the script and the errata: QQ's official platform rate-limits
bot session starts, and restarting eight times within an hour made the
qq_official adapter fail to log in. Batch deployments should batch restarts.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-27 05:42:03 +08:00
|
|
|
|
state=$(systemctl is-active astrbot)
|
|
|
|
|
|
restarts=$(systemctl show astrbot -p NRestarts --value)
|
|
|
|
|
|
echo "服务: $state NRestarts=$restarts"
|
|
|
|
|
|
[ "$state" = active ] || exit 1
|
|
|
|
|
|
plugin_errors=$(sudo journalctl -u astrbot --since "3 min ago" --no-pager 2>/dev/null \
|
|
|
|
|
|
| grep -E "ERRO|Traceback" | grep -ci companion || true)
|
|
|
|
|
|
echo "插件相关错误: $plugin_errors"
|
|
|
|
|
|
sudo journalctl -u astrbot --since "3 min ago" --no-pager 2>/dev/null \
|
|
|
|
|
|
| grep -E "Loading plugin astrbot_plugin_(memory|private)_companion_ops" || true
|
|
|
|
|
|
[ "$plugin_errors" = "0" ] || { echo "存在插件错误,考虑回滚" >&2; exit 1; }'
|
|
|
|
|
|
|
|
|
|
|
|
cat <<MSG
|
|
|
|
|
|
|
|
|
|
|
|
==> 完成。回滚:
|
|
|
|
|
|
BK=\$(sudo cat $BACKUP_ROOT/LATEST_M6)
|
|
|
|
|
|
sudo systemctl stop astrbot
|
|
|
|
|
|
sudo rm -rf $PLUGIN_DIR/astrbot_plugin_{memory,private}_companion_ops
|
|
|
|
|
|
sudo cp -r "\$BK/before-astrbot_plugin_memory_companion_ops" $PLUGIN_DIR/astrbot_plugin_memory_companion_ops
|
|
|
|
|
|
sudo cp -r "\$BK/before-astrbot_plugin_private_companion_ops" $PLUGIN_DIR/astrbot_plugin_private_companion_ops
|
|
|
|
|
|
sudo chown -R $OWNER $PLUGIN_DIR/astrbot_plugin_{memory,private}_companion_ops
|
|
|
|
|
|
sudo systemctl start astrbot
|
|
|
|
|
|
|
|
|
|
|
|
注意:QQ 官方平台对会话启动次数有限流,短时间内反复重启会让 qq_official
|
|
|
|
|
|
适配器登录失败(session_start_limit 为 None)。批量部署时请合并重启次数。
|
|
|
|
|
|
MSG
|