Improve server

This commit is contained in:
Jonas Nicklas 2009-11-07 15:35:47 +01:00
parent 351d5f2cf9
commit 00b75d8495
2 changed files with 21 additions and 18 deletions

View File

@ -8,7 +8,8 @@ module Webcat
attr_accessor :debug
def log(message)
puts message if debug
puts "[webcat] #{message}" if debug
true
end
end

View File

@ -9,7 +9,7 @@ class Webcat::Server
end
def port
9081
8080
end
def host
@ -21,25 +21,17 @@ class Webcat::Server
end
def boot
Webcat.log "[webcat] Booting Rack applicartion on port #{port}"
Webcat.log "application has already booted" and return if responsive?
Webcat.log "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"
Webcat.log "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"
Webcat.log("application has booted") and break if responsive?
if Time.now - start_time > 10
Webcat.log "Rack application timed out during boot"
exit
end
@ -47,5 +39,15 @@ class Webcat::Server
sleep 1
end
end
end
def responsive?
res = Net::HTTP.start(host, port) { |http| http.get('/') }
if res.is_a?(Net::HTTPSuccess) or res.is_a?(Net::HTTPRedirection)
return true
end
rescue Errno::ECONNREFUSED
return false
end
end