Method: Puma::SdNotify.notify

Defined in:
lib/puma/sd_notify.rb

.notify(state, unset_env = false) ⇒ Fixnum?

Notify systemd with the provided state, via the notification socket, if any.

Generally this method will be used indirectly through the other methods of the library.

Parameters:

  • state (String)
  • unset_env (Boolean) (defaults to: false)

Returns:

  • (Fixnum, nil)

    the number of bytes written to the notification socket or nil if there was no socket to report to (eg. the program wasn’t started by systemd)

Raises:

  • (NotifyError)

    if there was an error communicating with the systemd socket

See Also:



132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/puma/sd_notify.rb', line 132

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