Class: Vivarium::ApiServer
- Inherits:
-
Object
- Object
- Vivarium::ApiServer
- Defined in:
- lib/vivarium/api_server.rb
Overview
Minimal HTTP/1.1 server over a Unix domain socket exposing the daemon control API.
Constant Summary collapse
- STREAM_POLL_TIMEOUT =
1.0
Instance Method Summary collapse
-
#initialize(socket_path:, event_log:, registry:, daemon_pid: Process.pid) ⇒ ApiServer
constructor
A new instance of ApiServer.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(socket_path:, event_log:, registry:, daemon_pid: Process.pid) ⇒ ApiServer
Returns a new instance of ApiServer.
92 93 94 95 96 97 |
# File 'lib/vivarium/api_server.rb', line 92 def initialize(socket_path:, event_log:, registry:, daemon_pid: Process.pid) @socket_path = socket_path @event_log = event_log @registry = registry @daemon_pid = daemon_pid end |
Instance Method Details
#start ⇒ Object
99 100 101 102 103 104 105 106 |
# File 'lib/vivarium/api_server.rb', line 99 def start FileUtils.mkdir_p(File.dirname(@socket_path)) File.unlink(@socket_path) if File.exist?(@socket_path) @server = UNIXServer.new(@socket_path) File.chmod(0o666, @socket_path) @thread = Thread.new { accept_loop } self end |
#stop ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/vivarium/api_server.rb', line 108 def stop @server&.close rescue StandardError nil ensure File.unlink(@socket_path) if @socket_path && File.exist?(@socket_path) end |