2009-11-05 16:35:45 +00:00
|
|
|
require 'net/http'
|
2009-11-05 16:39:57 +00:00
|
|
|
require 'rack'
|
2009-11-05 16:35:45 +00:00
|
|
|
|
2009-11-04 22:00:05 +00:00
|
|
|
class Webcat::Server
|
|
|
|
attr_reader :app
|
|
|
|
|
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def port
|
|
|
|
9081
|
|
|
|
end
|
|
|
|
|
|
|
|
def host
|
|
|
|
'localhost'
|
|
|
|
end
|
|
|
|
|
|
|
|
def url(path)
|
|
|
|
"http://#{host}:#{port}#{path}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def boot
|
|
|
|
Webcat.log "[webcat] Booting Rack applicartion on port #{port}"
|
|
|
|
start_time = Time.now
|
|
|
|
Thread.new do
|
|
|
|
Rack::Handler::Mongrel.run @app, :Port => port
|
|
|
|
end
|
|
|
|
Webcat.log "[webcat] checking if application has booted"
|
|
|
|
loop do
|
|
|
|
begin
|
|
|
|
res = Net::HTTP.start(host, port) { |http| http.get('/') }
|
|
|
|
|
|
|
|
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
|
|
|
|
Webcat.log "[webcat] application has booted"
|
|
|
|
break
|
|
|
|
end
|
|
|
|
rescue Errno::ECONNREFUSED
|
|
|
|
end
|
|
|
|
|
|
|
|
if Time.now - start_time > 5
|
|
|
|
puts "[webcat] Rack application timed out during boot"
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
|
|
|
|
Webcat.log '.'
|
|
|
|
sleep 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|