Module: Raptor::Systemd
- Defined in:
- lib/raptor/systemd.rb,
sig/generated/raptor/systemd.rbs
Overview
Integration with systemd's service notification protocol and socket-activation file descriptors.
Constant Summary collapse
- LISTEN_FDS_START =
3- LISTEN_FDNAMES_ENV =
"LISTEN_FDNAMES"- LISTEN_FDS_ENV =
"LISTEN_FDS"- LISTEN_PID_ENV =
"LISTEN_PID"- NOTIFY_SOCKET_ENV =
"NOTIFY_SOCKET"
Class Method Summary collapse
-
.clear_listen_env ⇒ void
Clears the socket-activation environment variables so children don't act on stale values.
-
.listen_fds ⇒ Array<Integer>
Returns the file descriptors passed in via socket activation, or an empty array when systemd has not exported any.
-
.notify(message) ⇒ Boolean
Sends
messageto the systemd notification socket, returning true on success and false when the socket is unset or the send fails.
Class Method Details
.clear_listen_env ⇒ void
This method returns an undefined value.
Clears the socket-activation environment variables so children don't act on stale values.
63 64 65 66 67 |
# File 'lib/raptor/systemd.rb', line 63 def self.clear_listen_env ENV.delete(LISTEN_FDNAMES_ENV) ENV.delete(LISTEN_FDS_ENV) ENV.delete(LISTEN_PID_ENV) end |
.listen_fds ⇒ Array<Integer>
Returns the file descriptors passed in via socket activation, or an empty array when systemd has not exported any.
50 51 52 53 54 55 |
# File 'lib/raptor/systemd.rb', line 50 def self.listen_fds return [] unless ENV[LISTEN_PID_ENV]&.to_i == Process.pid count = ENV[LISTEN_FDS_ENV]&.to_i || 0 Array.new(count) { |index| LISTEN_FDS_START + index } end |
.notify(message) ⇒ Boolean
Sends message to the systemd notification socket, returning true on
success and false when the socket is unset or the send fails.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/raptor/systemd.rb', line 25 def self.notify() socket_path = ENV[NOTIFY_SOCKET_ENV] return false if socket_path.nil? || socket_path.empty? address = if socket_path.start_with?("@") Socket.pack_sockaddr_un("\0#{socket_path[1..]}") else Socket.pack_sockaddr_un(socket_path) end socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0) socket.send(, 0, address) true rescue SystemCallError, IOError false ensure socket&.close end |