Skip to content

Commit

Permalink
Send systemd notifications properly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
binford2k committed Sep 13, 2017
1 parent 72c35bb commit 85bfa56
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/abalone/watchdog.rb
Expand Up @@ -3,6 +3,11 @@ def initialize(period, options)
raise 'Watchdog needs a port to be set' unless options.include? :port
raise 'Watchdog needs a logger to be set' unless options.include? :logger
logger = options[:logger]
pid = Process.pid
socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0).tap do |socket|
socket.connect(Socket.pack_sockaddr_un(ENV['NOTIFY_SOCKET']))
socket.close_on_exec = true
end

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

0 comments on commit 85bfa56

Please sign in to comment.