Class: Kreuzberg::APIProxy::Server
- Inherits:
-
Object
- Object
- Kreuzberg::APIProxy::Server
- Defined in:
- lib/kreuzberg/api_proxy.rb
Overview
API server instance
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(port: 8000, host: '0.0.0.0') ⇒ Server
constructor
Initialize server.
-
#running? ⇒ Boolean
Check if server is running.
-
#start ⇒ Integer
Start the server in the background.
-
#stop ⇒ void
Stop the server.
Constructor Details
#initialize(port: 8000, host: '0.0.0.0') ⇒ Server
Initialize server
22 23 24 25 26 27 |
# File 'lib/kreuzberg/api_proxy.rb', line 22 def initialize(port: 8000, host: '0.0.0.0') @port = port @host = host @pid = nil @process = nil end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
15 16 17 |
# File 'lib/kreuzberg/api_proxy.rb', line 15 def host @host end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
15 16 17 |
# File 'lib/kreuzberg/api_proxy.rb', line 15 def pid @pid end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
15 16 17 |
# File 'lib/kreuzberg/api_proxy.rb', line 15 def port @port end |
Instance Method Details
#running? ⇒ Boolean
Check if server is running
67 68 69 70 71 72 73 74 |
# File 'lib/kreuzberg/api_proxy.rb', line 67 def running? return false unless @pid Process.kill(0, @pid) true rescue Errno::ESRCH, Errno::EPERM false end |
#start ⇒ Integer
Start the server in the background
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kreuzberg/api_proxy.rb', line 34 def start binary = APIProxy.find_api_binary @pid = spawn( binary.to_s, 'api', '--host', @host, '--port', @port.to_s, out: $stdout, err: $stderr ) Process.detach(@pid) sleep 1 @pid end |
#stop ⇒ void
This method returns an undefined value.
Stop the server
53 54 55 56 57 58 59 60 61 |
# File 'lib/kreuzberg/api_proxy.rb', line 53 def stop return unless @pid Process.kill('TERM', @pid) Process.wait(@pid) rescue Errno::ESRCH, Errno::ECHILD # rubocop:disable Lint/SuppressedException ensure @pid = nil end |