Created
October 3, 2008 14:10
-
-
Save jamesu/14562 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Detects what server your Rails app is running under. | |
# Either passenger, fastcgi, mongrel, webrick or thin | |
def running_under | |
# For passenger, IN_PHUSION_PASSENGER is key | |
is_passenger = (defined?(IN_PHUSION_PASSENGER) and IN_PHUSION_PASSENGER) | |
# Not sure about fastcgi, but this should do the trick | |
is_fastcgi = (Kernel.const_get('RailsFCGIHandler') if defined?(FCGI)) rescue false | |
# Webrick is require'd only as a last resort | |
is_webrick = !defined?(WEBrick).nil? | |
# For mongrel and thin, seems best to look for instances | |
is_mongrel = false | |
ObjectSpace.each_object(Mongrel::HttpHandler) { is_mongrel = true; break; } if defined?(Mongrel) | |
is_thin = false | |
ObjectSpace.each_object(Thin::Runner) { is_thin = true; break; } if defined?(Thin) | |
# Earlier versions of passenger don't have IN_PHUSION_PASSENGER, so here's a workaround | |
unless is_fastcgi or is_mongrel or is_webrick or is_thin | |
is_passenger = defined?(Passenger) and Passenger.class == Module | |
end | |
if is_passenger | |
"Passenger" | |
elsif is_fastcgi | |
"FastCGI" | |
elsif is_mongrel | |
"Mongrel" | |
elsif is_webrick | |
"WEBrick" | |
elsif is_thin | |
"Thin" | |
else | |
"Unknown" | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment