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
+36
View File
@@ -0,0 +1,36 @@
# frozen_string_literal: true
class SystemdNotifier
require_relative 'method_executor'
public
@notify_socket = ENV["NOTIFY_SOCKET"]
@watchdog_usec = (ENV["WATCHDOG_USEC"] || '0').to_i
unless @notify_socket && File.socket?(@notify_socket)
MethodExecutor.record("error", "heartbeat", "NOTIFY_SOCKET is not set or is not a socket, am I a service?")
@enable_heartbeat = false
else
@enable_heartbeat = true
@socket = UNIXSocket.new(@notify_socket)
end
def enabled?
@enable_heartbeat
end
def notify_heartbeat(message)
return unless @enable_heartbeat
begin
@socket.send(message, 0)
rescue => e
MethodExecutor.error("heartbeat", "Failed to send heartbeat: #{e}")
@enable_heartbeat = false
end
end
def self.notify(message)
MethodExecutor.record("info", "systemd", message)
end
end