Skip to content

Instantly share code, notes, and snippets.

@bopm
Created December 8, 2010 15:50
Show Gist options
  • Save bopm/733453 to your computer and use it in GitHub Desktop.
Save bopm/733453 to your computer and use it in GitHub Desktop.
module for getting current "port" in mongrel/unicorn environment
module ServerInfo
def server_port
port = nil
if (defined?(::Mongrel) && defined?(::Mongrel::HttpServer))
ObjectSpace.each_object(Mongrel::HttpServer) do |mongrel|
@mongrel = mongrel
end
port = @mongrel.andand.port
end
if (defined?(::Unicorn) && defined?(::Unicorn::HttpServer))
ObjectSpace.each_object(Unicorn::HttpServer) do |unicorn|
@unicorn = unicorn
end
port = $0.gsub(/.*worker\[(\d+)\].*/, '\1') if @unicorn
end
port
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment