module Puma::SdNotify

def self.errno(errno, unset_env=false)

Parameters:
  • errno (Integer) --
def self.errno(errno, unset_env=false)
  notify("#{ERRNO}#{errno}", unset_env)
end

def self.fdstore(unset_env=false)

def self.fdstore(unset_env=false)
  notify(FDSTORE, unset_env)
end

def self.mainpid(pid, unset_env=false)

Parameters:
  • pid (Integer) --
def self.mainpid(pid, unset_env=false)
  notify("#{MAINPID}#{pid}", unset_env)
end

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 if !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 StandardError => e
    raise NotifyError, "#{e.class}: #{e.message}", e.backtrace
  end
end

def self.ready(unset_env=false)

def self.ready(unset_env=false)
  notify(READY, unset_env)
end

def self.reloading(unset_env=false)

def self.reloading(unset_env=false)
  notify(RELOADING, unset_env)
end

def self.status(status, unset_env=false)

Parameters:
  • status (String) -- a custom status string that describes the current
def self.status(status, unset_env=false)
  notify("#{STATUS}#{status}", unset_env)
end

def self.stopping(unset_env=false)

def self.stopping(unset_env=false)
  notify(STOPPING, unset_env)
end

def self.watchdog(unset_env=false)

def self.watchdog(unset_env=false)
  notify(WATCHDOG, unset_env)
end

def self.watchdog?

Other tags:
    Note: - Unlike sd_watchdog_enabled(3), this method does not mutate the

Parameters:
  • true (Boolean) -- if the service manager expects watchdog keep-alive
def self.watchdog?
  wd_usec = ENV["WATCHDOG_USEC"]
  wd_pid = ENV["WATCHDOG_PID"]
  return false if !wd_usec
  begin
    wd_usec = Integer(wd_usec)
  rescue
    return false
  end
  return false if wd_usec <= 0
  return true if !wd_pid || wd_pid == $$.to_s
  false
end