Skip to content

Commit 85bfa56

Browse files
authored
Send systemd notifications properly
There's a bug in `systemd-notify` such that the command sends the message and then exits. Since its lifetime is so short, systemd doesn't have time to do the housekeeping to figure out which service unit to associate it with. The mitigation is to just open the socket and send the message directly ourselves, since our process is long-lived. See systemd/systemd#2737 Fixes #16
1 parent 72c35bb commit 85bfa56

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/abalone/watchdog.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ def initialize(period, options)
33
raise 'Watchdog needs a port to be set' unless options.include? :port
44
raise 'Watchdog needs a logger to be set' unless options.include? :logger
55
logger = options[:logger]
6+
pid = Process.pid
7+
socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0).tap do |socket|
8+
socket.connect(Socket.pack_sockaddr_un(ENV['NOTIFY_SOCKET']))
9+
socket.close_on_exec = true
10+
end
611

712
Thread.new do
813
require 'net/http'
@@ -17,7 +22,8 @@ def initialize(period, options)
1722
http.start
1823
http.request_get('/heartbeat/ping') do |res|
1924
logger.debug "Heartbeat response: #{res.read_body}"
20-
system('systemd-notify WATCHDOG=1')
25+
#system('systemd-notify WATCHDOG=1')
26+
socket.write("WATCHDOG=1\nMAINPID=#{pid}")
2127
end
2228
rescue => e
2329
logger.warn 'Abalone service failed heartbeat check!'

0 commit comments

Comments
 (0)