2026-06-08 07:51:00 +08:00
2026-06-07 20:41:14 +08:00
2026-06-07 20:41:14 +08:00
2026-06-07 19:35:17 +08:00
2026-06-07 19:35:17 +08:00
2026-06-07 19:35:17 +08:00
2026-06-07 19:35:17 +08:00
2026-06-07 19:35:17 +08:00

MineSentinel

🛡️  MineSentinel
Minecraft 服务器守护进程

TCP 端口检测 · 崩溃自动重启 · 冷却期防循环

License Ruby Platform

快速开始

# 复制文件
mkdir -p /opt/minecraft/sentinel
cp main.rb method_executor.rb server_status_detector.rb /opt/minecraft/sentinel/

# 安装 systemd 服务
cp minesentinel.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable minesentinel
systemctl start minesentinel

# 手动运行(调试用)
cd /opt/minecraft/sentinel
ruby main.rb

特性

  • 高频检测 — 每 1.5 秒 TCP 连接 127.0.0.1:25565
  • 智能判断 — 端口超时仅记录日志,端口关闭才触发重启
  • 冷却期保护 — 重启后等待 200 秒,防止 MC 启动缓慢导致循环重启
  • 初始宽限期 — MineSentinel 先于 minecraft 启动,自动等待 300 秒至端口就绪
  • 重试上限 — 连续 10 次失败进入空闲等待,端口恢复后自动退出
  • 多场景适配 — 支持 systemd / Docker / screen / Windows

服务启动顺序

开机 → network.target
         │
    ┌────▼────────┐
    │ MineSentinel │  最先启动,进入 300s 宽限期等待 MC 就绪
    └────┬────────┘
         │ Before=
    ┌────▼────┐
    │minecraft │  随后启动,TCP 端口打开后 MineSentinel 恢复正常监控
    └─────────┘

MineSentinel 通过 Before=minecraft.service 确保先于 MC 启动,避免 MC 先启动后崩溃而未被守护的第一时间窗口。首次启动的 300 秒宽限期确保不会把 MC 的正常启动过程误判为崩溃。

文件说明

文件 职责
main.rb 主循环、冷却期控制、初始宽限期
method_executor.rb 日志系统、systemctl 重启、计数器
server_status_detector.rb TCP 端口检测模块
minesentinel.service systemd 单元文件(独立源码)

完整文档

参见 DEPLOY.md官网

许可证

MulanPubL v2.0 — Copyright © 2026 S.A. SNOWARE-SCU

品牌标识(Logo / 项目名称)保留所有权利,未经许可不得用于衍生项目。

S
Description
mc服务器监视与重启
Readme 699 KiB
Languages
HTML 79.5%
Ruby 20.5%