lib/trinidad/web_app.rb in trinidad-1.1.1 vs lib/trinidad/web_app.rb in trinidad-1.2.0
- old
+ new
@@ -1,10 +1,12 @@
module Trinidad
class WebApp
attr_reader :config, :app_config, :class_loader, :servlet
def self.create(config, app_config)
+ autodetect_configuration(config, app_config)
+
war?(app_config) ? WarWebApp.new(config, app_config) :
rackup?(app_config) ? RackupWebApp.new(config, app_config) : RailsWebApp.new(config, app_config)
end
def self.rackup?(app_config)
@@ -94,10 +96,14 @@
def monitor
m_file = @app_config[:monitor] || @config[:monitor] || 'tmp/restart.txt'
File.expand_path(m_file, work_dir)
end
+ def define_lifecycle
+ Trinidad::Lifecycle::Default.new(self)
+ end
+
protected
def add_parameter_unless_exist(param_name, param_value)
@params[param_name] = param_value unless web_context_param(param_name)
end
@@ -126,8 +132,33 @@
if servlet_config
servlet_class = servlet_config[:class]
servlet_name = servlet_config[:name]
end
@servlet = {:class => servlet_class, :name => servlet_name}
+ end
+
+ def self.autodetect_configuration(config, app_config)
+ # Check for Rails threadsafe mode
+ environment = app_config[:environment] || config[:environment]
+ if threadsafe_instance?(app_config[:web_app_dir], environment)
+ app_config[:jruby_min_runtimes] = 1
+ app_config[:jruby_max_runtimes] = 1
+ end
+
+ # Check for rackup (but still use config/environment.rb for Rails 3)
+ if !app_config[:rackup] && !config[:rackup] &&
+ File.exists?("#{app_config[:web_app_dir]}/config.ru") &&
+ !File.exists?("#{app_config[:web_app_dir]}/config/environment.rb")
+ app_config[:rackup] = 'config.ru'
+ end
+ end
+
+ def self.threadsafe_instance?(app_base, environment)
+ threadsafe_match?("#{app_base}/config/environments/#{environment}.rb") ||
+ threadsafe_match?("#{app_base}/config/environment.rb")
+ end
+
+ def self.threadsafe_match?(file)
+ File.exist?(file) && File.readlines(file).any? { |l| l =~ /^[^#]*threadsafe!/ }
end
end
end