From 3accd84bd1fdffc90b0167b33d8b6f6b5060bb5e Mon Sep 17 00:00:00 2001 From: liuwei Date: Wed, 29 Apr 2026 11:58:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E240=E6=9C=AC=E6=9C=BA?= =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E8=84=9A=E6=9C=AC=E5=B9=B6=E5=8C=85=E5=90=AB?= =?UTF-8?q?=E5=81=9C=E6=AD=A2MaiBot=E8=83=BD=E5=8A=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 变更项:\n1. 新增 plugins/maibot_adapter/maibot_maintenance.sh,可在服务器本机直接执行。\n2. 提供 stop 动作用于停止 maibot-core-lite 容器,满足手动停服诉求。\n3. 同时补充 status/start/restart/logs/health 动作,便于日常运维排障。\n4. 脚本支持通过 CONTAINER_NAME/WEBUI_PORT 环境变量覆盖默认值。 --- plugins/maibot_adapter/maibot_maintenance.sh | 80 ++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 plugins/maibot_adapter/maibot_maintenance.sh diff --git a/plugins/maibot_adapter/maibot_maintenance.sh b/plugins/maibot_adapter/maibot_maintenance.sh new file mode 100644 index 0000000..f14bd4e --- /dev/null +++ b/plugins/maibot_adapter/maibot_maintenance.sh @@ -0,0 +1,80 @@ +#!/usr/bin/env bash +# MaiBot 本机维护脚本(在 240 上执行) +# 用法示例: +# bash maibot_maintenance.sh stop +# bash maibot_maintenance.sh status +# bash maibot_maintenance.sh restart + +set -euo pipefail + +CONTAINER_NAME="${CONTAINER_NAME:-maibot-core-lite}" +WEBUI_PORT="${WEBUI_PORT:-18001}" + +print_help() { + cat <<'EOF' +用法: + maibot_maintenance.sh + +动作: + status 查看容器状态 + stop 停止 MaiBot 容器 + start 启动 MaiBot 容器 + restart 重启 MaiBot 容器 + logs 查看最近日志(默认 10 分钟) + health 检查 WebUI 健康接口 + +可选环境变量: + CONTAINER_NAME 默认 maibot-core-lite + WEBUI_PORT 默认 18001 +EOF +} + +action="${1:-}" + +if [[ -z "${action}" ]]; then + print_help + exit 1 +fi + +case "${action}" in + status) + echo "[INFO] 容器状态:" + docker ps -a --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}' | head -n 1 + docker ps -a --format 'table {{.Names}}\t{{.Image}}\t{{.Status}}' | grep "${CONTAINER_NAME}" || true + ;; + + stop) + echo "[INFO] 正在停止容器: ${CONTAINER_NAME}" + docker stop "${CONTAINER_NAME}" + echo "[INFO] 已停止" + ;; + + start) + echo "[INFO] 正在启动容器: ${CONTAINER_NAME}" + docker start "${CONTAINER_NAME}" + echo "[INFO] 已启动" + ;; + + restart) + echo "[INFO] 正在重启容器: ${CONTAINER_NAME}" + docker restart "${CONTAINER_NAME}" + echo "[INFO] 已重启" + ;; + + logs) + echo "[INFO] 最近 10 分钟关键日志:" + docker logs --since 10m "${CONTAINER_NAME}" 2>&1 | grep -aE "Timing Gate|no_reply|reply|SendService|platform_map|Bridge received|发送|回复" || true + ;; + + health) + echo "[INFO] 检查健康接口: http://127.0.0.1:${WEBUI_PORT}/api/webui/health" + curl -sS --max-time 8 "http://127.0.0.1:${WEBUI_PORT}/api/webui/health" || true + echo + ;; + + *) + echo "[ERROR] 未知动作: ${action}" + print_help + exit 2 + ;; +esac