module Sidekiq::SdNotify

def self.notify(state, unset_env = false)

Other tags:
    See: https://www.freedesktop.org/software/systemd/man/sd_notify.html -

Raises:
  • (NotifyError) - if there was an error communicating with the systemd

Returns:
  • (Fixnum, nil) - the number of bytes written to the notification

Parameters:
  • unset_env (Boolean) --
  • state (String) --
def self.notify(state, unset_env = false)
  sock = ENV["NOTIFY_SOCKET"]
  return nil unless sock
  ENV.delete("NOTIFY_SOCKET") if unset_env
  begin
    Addrinfo.unix(sock, :DGRAM).connect do |s|
      s.close_on_exec = true
      s.write(state)
    end
  rescue => e
    raise NotifyError, "#{e.class}: #{e.message}", e.backtrace
  end
end