Ondra Ondra - 6 months ago 23
Ruby Question

How to detect, that server is started in Sinatra/Thin

I have code like:

Thread.new do
builder = Rack::Builder.new do
map('/'){ run Server }
end
Rack::Handler::Thin.run builder, :Port => 8585
end
#how do i detect, that Server is running here (or wait for it)


How can i detect, that Server is running and able to receive requests?

Thanks

Answer

You can use the defined? method to check for this, e.g.

if defined? Rack::Handler::Thin
   # We're running under Thin. Do stuff.
else
   # nope :(
end