Class: Eir::Server
- Inherits:
-
Object
show all
- Defined in:
- lib/eir/server.rb
Defined Under Namespace
Classes: FailedToStartSinatraError, FailedToStopSinatraError
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
3
4
5
|
# File 'lib/eir/server.rb', line 3
def initialize
@server_url = 'http://localhost:8700'
end
|
Instance Method Details
#start ⇒ Object
25
26
27
28
29
30
|
# File 'lib/eir/server.rb', line 25
def start
stop if File.exist? 'server.pid'
puts "Starting the server at #{@server_url}"
`bundle exec puma --config #{File.dirname(__FILE__)}/app/puma.rb`
Timeout.timeout(10, FailedToStartSinatraError) { sleep 1 until status == 200 }
end
|
#status ⇒ Object
19
20
21
22
23
|
# File 'lib/eir/server.rb', line 19
def status
RestClient.get("#{@server_url}/status").code
rescue Errno::ECONNREFUSED
false
end
|
#stop ⇒ Object
32
33
34
35
36
37
|
# File 'lib/eir/server.rb', line 32
def stop
pid = File.read('server.pid').to_i
puts "Destroying the server process ID: #{pid}"
`kill -9 #{pid}`
Timeout.timeout(10, FailedToStopSinatraError) { sleep 1 until status == false }
end
|