# <<*>> -^v- SNOWARE APPLICATION # usage: MINESENTINEL mainloop. # author: S.A. # time: 2026-06-07 # license: All rights received. # main.rb 顶部添加 begin # 原有代码 rescue => e # 强制输出到stderr $stderr.puts "[CRITICAL] Unhandled exception: #{e.message}" $stderr.puts e.backtrace.join("\n") exit 1 end require_relative 'method_executor' # 日志系统在此时初始化 require_relative 'server_status_detector' MethodExecutor.record("info", "mainloop", "MineSentinel started, entering mainloop.") # Functional mainloop. def main chkrslt = ServerStatusDetector::MinecraftServer.self_diag if chkrslt[:type] MethodExecutor.record("debug", "mainloop", "Server health check passed.") else MethodExecutor.record("warn", "mainloop", "Server health check FAILED: #{chkrslt[:message]}") for operation in chkrslt[:operation] if operation == "Record" # 消息已在 self_diag 中生成,这里仅记录操作 MethodExecutor.record("warn", "mainloop", "Action: Record -> Server died!") elsif operation == "ForceResetServerProcess" MethodExecutor.record("info", "mainloop", "Action: ForceResetServerProcess triggered.") MethodExecutor.reset_minecraft_server # 重启后等待服务器启动(MC服务器启动通常需要30秒~2分钟) cooldown = 190 # 190秒冷却期 MethodExecutor.record("info", "mainloop", "Cooling down #{cooldown}s for server startup...") sleep cooldown MethodExecutor.record("info", "mainloop", "Cooldown finished, resuming monitoring.") end end end end while true sleep 1.5 main end