class Async::Container::Notify::Socket
See <www.freedesktop.org/software/systemd/man/sd_notify.html> for more details of the underlying protocol.
Implements the systemd NOTIFY_SOCKET process readiness protocol.
def self.open!(environment = ENV)
def self.open!(environment = ENV) if path = environment.delete(NOTIFY_SOCKET) self.new(path) end end
def dump(message)
Dump a message in the format requied by `sd_notify`.
def dump(message) buffer = String.new message.each do |key, value| # Conversions required by NOTIFY_SOCKET specifications: if value == true value = 1 elsif value == false value = 0 end buffer << "#{key.to_s.upcase}=#{value}\n" end return buffer end
def error!(text, **message)
Send the specified error.
def error!(text, **message) message[:errno] ||= -1 super end
def initialize(path)
Initialize the notification client.
def initialize(path) @path = path @address = Addrinfo.unix(path, ::Socket::SOCK_DGRAM) end
def send(**message)
Send the given message.
def send(**message) data = dump(message) if data.bytesize > MAXIMUM_MESSAGE_SIZE raise ArgumentError, "Message length #{data.bytesize} exceeds #{MAXIMUM_MESSAGE_SIZE}: #{message.inspect}" end @address.connect do |peer| peer.sendmsg(data) end end