lib/trinidad/server.rb in trinidad-0.9.10 vs lib/trinidad/server.rb in trinidad-0.9.11

- old
+ new

@@ -33,34 +33,55 @@ @tomcat = Trinidad::Tomcat::Tomcat.new @tomcat.hostname = @config[:address] @tomcat.server.address = @config[:address] @tomcat.port = @config[:port].to_i @tomcat.base_dir = Dir.pwd - @tomcat.host.app_base = Dir.pwd + @tomcat.host.app_base = @config[:apps_base] || Dir.pwd @tomcat.enable_naming add_http_connector if http_configured? add_ssl_connector if ssl_enabled? add_ajp_connector if ajp_enabled? @tomcat = Trinidad::Extensions.configure_server_extensions(@config[:extensions], @tomcat) end def create_web_apps - @config[:web_apps].each do |name, app_config| - app_config[:context_path] ||= (name.to_s == 'default' ? '/' : "/#{name.to_s}") - app_config[:web_app_dir] ||= Dir.pwd + if @config[:web_apps] + @config[:web_apps].each do |name, app_config| + app_config[:context_path] ||= (name.to_s == 'default' ? '/' : "/#{name.to_s}") + app_config[:web_app_dir] ||= Dir.pwd + create_web_app(app_config) + end + end + if @config[:apps_base] + apps_path = Dir.glob(File.join(@config[:apps_base], '*')).select {|path| !(path =~ /tomcat\.8080$/) } + + apps_path.each do |path| + if File.directory?(path) + name = File.basename(path) + app_config = { + :context_path => (name == 'default' ? '/' : "/#{name.to_s}"), + :web_app_dir => File.expand_path(path) + } + + create_web_app(app_config) + end + end + end + end + + def create_web_app(app_config) app_context = @tomcat.addWebapp(app_config[:context_path], app_config[:web_app_dir]) remove_defaults(app_context) web_app = WebApp.create(@config, app_config) configure_logging(web_app) Trinidad::Extensions.configure_webapp_extensions(web_app.extensions, @tomcat, app_context) app_context.add_lifecycle_listener(WebAppLifecycleListener.new(web_app)) - end end def add_service_connector(options, protocol = nil) connector = Trinidad::Tomcat::Connector.new(protocol) @@ -84,11 +105,11 @@ add_service_connector(@config[:ajp], 'AJP/1.3') end def add_ssl_connector options = @config[:ssl].merge({ - :scheme => 'https', + :scheme => 'https', :secure => true, :SSLEnabled => 'true' }) options[:keystoreFile] ||= options.delete(:keystore) @@ -129,16 +150,16 @@ if (!keystore_file.parent_file.exists && !keystore_file.parent_file.mkdir) raise "Unable to create keystore folder: " + keystore_file.parent_file.canonical_path end - keytool_args = ["-genkey", - "-alias", "localhost", - "-dname", "CN=localhost, OU=Trinidad, O=Trinidad, C=ES", + keytool_args = ["-genkey", + "-alias", "localhost", + "-dname", "CN=localhost, OU=Trinidad, O=Trinidad, C=ES", "-keyalg", "RSA", - "-validity", "365", - "-storepass", "key", + "-validity", "365", + "-storepass", "key", "-keystore", config[:keystoreFile], "-storepass", config[:keystorePass], "-keypass", config[:keystorePass]] Trinidad::Tomcat::KeyTool.main(keytool_args.to_java(:string)) @@ -150,10 +171,10 @@ end private def add_default_web_app!(config) - unless (config.has_key?(:web_apps)) + if (!config.has_key?(:web_apps) && !config.has_key?(:apps_base)) default_app = { :context_path => config[:context_path] || '/', :web_app_dir => config[:web_app_dir] || Dir.pwd, :log => config[:log] }