# MineSentinel ``` 🛡️ MineSentinel Minecraft 服务器守护进程 ``` **TCP 端口检测 · 崩溃自动重启 · 冷却期防循环** [![License](https://img.shields.io/badge/License-MulanPubL--2.0-orange.svg)](http://license.coscl.org.cn/MulanPubL-2.0) [![Ruby](https://img.shields.io/badge/Ruby-%3E%3D3.0-cc342d?logo=ruby)](https://www.ruby-lang.org) [![Platform](https://img.shields.io/badge/Platform-Linux%20%7C%20Windows-blue)](#跨场景适配指南) ## 快速开始 ```bash # 复制文件 mkdir -p /opt/minecraft/sentinel cp main.rb method_executor.rb server_status_detector.rb systemd_notifier.rb config.rb updates.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 端口检测模块 | | `systemd_notifier.rb` | systemd watchdog 心跳发送 | | `config.rb` | 可调参数配置 | | `updates.rb` | 更新检查模块 | | `minesentinel.service` | systemd 单元文件(独立源码) | ## 完整文档 参见 [DEPLOY.md](DEPLOY.md) 或 [官网](OfficialWebsite/index.html)。 ## 许可证 [MulanPubL v2.0](http://license.coscl.org.cn/MulanPubL-2.0) — Copyright © 2026 S.A. SNOWARE-SCU > 品牌标识(Logo / 项目名称)保留所有权利,未经许可不得用于衍生项目。