新增240本机维护脚本并包含停止MaiBot能力
变更项:\n1. 新增 plugins/maibot_adapter/maibot_maintenance.sh,可在服务器本机直接执行。\n2. 提供 stop 动作用于停止 maibot-core-lite 容器,满足手动停服诉求。\n3. 同时补充 status/start/restart/logs/health 动作,便于日常运维排障。\n4. 脚本支持通过 CONTAINER_NAME/WEBUI_PORT 环境变量覆盖默认值。
This commit is contained in:
80
plugins/maibot_adapter/maibot_maintenance.sh
Normal file
80
plugins/maibot_adapter/maibot_maintenance.sh
Normal file
@@ -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 <action>
|
||||
|
||||
动作:
|
||||
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
|
||||
Reference in New Issue
Block a user