Fix systemd misjudging by sending heartbeats.

This commit is contained in:
2026-06-08 07:30:21 +08:00
parent c826d7237c
commit c61ffe2f75
3 changed files with 46 additions and 3 deletions
+8 -2
View File
@@ -24,6 +24,7 @@ end
require_relative 'method_executor' # 日志系统在此时初始化
require_relative 'server_status_detector'
require_relative 'systemd_notifier' # 心跳系统在此时初始化
MethodExecutor.record("info", "mainloop", "MineSentinel started, entering mainloop.")
@@ -58,9 +59,13 @@ def main
MethodExecutor.record("info", "mainloop", "Action: ForceResetServerProcess triggered.")
MethodExecutor.reset_minecraft_server
# 重启后等待服务器启动(MC服务器启动通常需要30秒~2分钟)
cooldown = 200 # 200秒冷却期
cooldown_duration = 200 # 200秒冷却期
cooldown_beg = Time.now
MethodExecutor.record("info", "mainloop", "Cooling down #{cooldown}s for server startup...")
sleep cooldown
while Time.now < cooldown_beg + cooldown_duration
sleep 1
SystemdNotifier.notify("WATCHDOG=1")
end
MethodExecutor.record("info", "mainloop", "Cooldown finished, resuming monitoring.")
end
end
@@ -70,5 +75,6 @@ end
while true
sleep 1.5
SystemdNotifier.notify("WATCHDOG=1")
main
end