46 lines
1.3 KiB
Ruby
46 lines
1.3 KiB
Ruby
# <<*>> -^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
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
while true
|
|
sleep 1.5
|
|
main
|
|
end
|