Class: Trinidad::Server
- Inherits:
-
Object
- Object
- Trinidad::Server
- Defined in:
- lib/trinidad/server.rb
Constant Summary collapse
- DEFAULT_KEYSTORE_FILE =
'ssl/keystore'
Instance Attribute Summary collapse
-
#ajp_enabled ⇒ Object
writeonly
Sets the attribute ajp_enabled.
- #app_base ⇒ Object
-
#config ⇒ Object
readonly
Returns the value of attribute config.
- #hosts ⇒ Object
-
#ssl_enabled ⇒ Object
(also: #https_enabled=)
writeonly
Sets the attribute ssl_enabled.
-
#trap ⇒ Object
writeonly
Sets the attribute trap.
- #web_apps ⇒ Object
Instance Method Summary collapse
- #add_ajp_connector(options = , tomcat = nil) ⇒ Object
- #add_http_connector(options = , tomcat = nil) ⇒ Object
-
#add_ssl_connector(options = , tomcat = nil) ⇒ Object
TODO review default location.
- #add_web_app(web_app, host = nil, start = nil) ⇒ Object
- #ajp_enabled? ⇒ Boolean
- #configure(config = Trinidad.configuration) ⇒ Object
- #deploy_web_apps(tomcat = self.tomcat) ⇒ Object
- #http_configured=(flag) ⇒ Object deprecated Deprecated.
- #http_configured? ⇒ Boolean
-
#initialize(config = Trinidad.configuration) ⇒ Server
constructor
A new instance of Server.
-
#load_config(config) ⇒ Object
deprecated
Deprecated.
replaced with #configure
-
#load_host_monitor(web_apps) ⇒ Object
deprecated
Deprecated.
replaced with #setup_host_monitor
-
#load_tomcat_server ⇒ Object
#deprecated renamed to #initialize_tomcat.
- #ssl_enabled? ⇒ Boolean (also: #https_enabled?)
- #start ⇒ Object
- #start! ⇒ Object
- #stop ⇒ Object
- #stop! ⇒ Object
- #tomcat ⇒ Object
- #trap? ⇒ Boolean
Constructor Details
#initialize(config = Trinidad.configuration) ⇒ Server
Returns a new instance of Server.
8 9 10 |
# File 'lib/trinidad/server.rb', line 8 def initialize(config = Trinidad.configuration) configure(config) end |
Instance Attribute Details
#ajp_enabled=(value) ⇒ Object (writeonly)
Sets the attribute ajp_enabled
58 59 60 |
# File 'lib/trinidad/server.rb', line 58 def ajp_enabled=(value) @ajp_enabled = value end |
#app_base ⇒ Object
24 25 26 |
# File 'lib/trinidad/server.rb', line 24 def app_base @app_base ||= @config[:app_base] || @config[:apps_base] end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/trinidad/server.rb', line 6 def config @config end |
#hosts ⇒ Object
19 20 21 |
# File 'lib/trinidad/server.rb', line 19 def hosts @hosts ||= @config[:hosts] end |
#ssl_enabled=(value) ⇒ Object (writeonly) Also known as: https_enabled=
Sets the attribute ssl_enabled
47 48 49 |
# File 'lib/trinidad/server.rb', line 47 def ssl_enabled=(value) @ssl_enabled = value end |
#trap=(value) ⇒ Object (writeonly)
Sets the attribute trap
38 39 40 |
# File 'lib/trinidad/server.rb', line 38 def trap=(value) @trap = value end |
#web_apps ⇒ Object
29 30 31 |
# File 'lib/trinidad/server.rb', line 29 def web_apps @web_apps ||= @config[:web_apps] || @config[:webapps] end |
Instance Method Details
#add_ajp_connector(options = , tomcat = nil) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/trinidad/server.rb', line 125 def add_ajp_connector( = config[:ajp], tomcat = nil) # backwards compatibility - single argument (tomcat = @tomcat) if && ! .respond_to?(:[]) tomcat = ; = config[:ajp] else tomcat = @tomcat end if tomcat.nil? = .respond_to?(:[]) ? .dup : {} [:address] = config[:address] unless .key?(:address) add_service_connector(, 'AJP/1.3', tomcat) end |
#add_http_connector(options = , tomcat = nil) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/trinidad/server.rb', line 139 def add_http_connector( = config[:http], tomcat = nil) # backwards compatibility - single argument (tomcat = @tomcat) if && ! .respond_to?(:[]) tomcat = ; = config[:http] else tomcat = @tomcat end if tomcat.nil? = .respond_to?(:[]) ? .dup : {} [:port] = config[:port] || 3000 unless .key?(:port) [:address] = config[:address] unless .key?(:address) if .delete(:nio) [:protocol_handler] ||= 'org.apache.coyote.http11.Http11NioProtocol' end if .delete(:apr) tomcat.server.add_lifecycle_listener(Tomcat::AprLifecycleListener.new) end add_service_connector(, 'HTTP/1.1', tomcat) end |
#add_ssl_connector(options = , tomcat = nil) ⇒ Object
TODO review default location
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/trinidad/server.rb', line 165 def add_ssl_connector( = config[:ssl], tomcat = nil) # backwards compatibility - single argument (tomcat = @tomcat) if && ! .respond_to?(:[]) tomcat = ; = config[:ssl] else tomcat = @tomcat end if tomcat.nil? = { :scheme => 'https', :secure => true }.merge!( .respond_to?(:[]) ? : {} ) [:address] = config[:address] unless .key?(:address) if keystore_file = .delete(:keystore) || .delete(:keystore_file) [:keystoreFile] ||= keystore_file end [:keystorePass] ||= .delete(:keystore_pass) if .key?(:keystore_pass) # handle "custom" alternative SSL (casing) options : [:SSLEnabled] = .delete(:ssl_enabled) || true # always true [:SSLCertificateFile] ||= .delete(:ssl_certificate_file) if .key?(:ssl_certificate_file) [:SSLCertificateKeyFile] ||= .delete(:ssl_certificate_key_file) if .key?(:ssl_certificate_key_file) [:SSLVerifyClient] ||= .delete(:ssl_verify_client) if .key?(:ssl_verify_client) [:SSLProtocol] ||= .delete(:ssl_protocol) if .key?(:ssl_protocol) # NOTE: there's quite more SSL prefixed options with APR ... if ! [:keystoreFile] && ! [:SSLCertificateFile] # generate one for development/testing SSL : [:keystoreFile] = DEFAULT_KEYSTORE_FILE [:keystorePass] ||= 'waduswadus42' # NOTE change/ask for default if File.exist?(DEFAULT_KEYSTORE_FILE) logger.info "Using (default) keystore at #{DEFAULT_KEYSTORE_FILE.inspect}" else generate_default_keystore() end end add_service_connector(, 'HTTP/1.1', tomcat) end |
#add_web_app(web_app, host = nil, start = nil) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/trinidad/server.rb', line 220 def add_web_app(web_app, host = nil, start = nil) host ||= begin name = web_app.host_name name ? find_host(name, tomcat) : tomcat.host end prev_start = host.start_children context = begin host.start_children = start unless start.nil? # public Context addWebapp(Host host, String url, String name, String docBase) tomcat.addWebapp(host, web_app.context_path, web_app.context_name, web_app.root_dir) rescue Java::JavaLang::IllegalArgumentException => e if e. =~ /addChild\:/ context_name = web_app.context_name logger.error "could not add application #{context_name.inspect} from #{web_app.root_dir}\n" << " (same context name is used for #{host.find_child(context_name).doc_base})" raise "there's already an application named #{context_name.inspect} for host #{host.name.inspect}" end raise e ensure host.start_children = prev_start unless start.nil? end Extensions.configure_webapp_extensions(web_app.extensions, tomcat, context) if lifecycle = web_app.define_lifecycle context.add_lifecycle_listener(lifecycle) end context end |
#ajp_enabled? ⇒ Boolean
51 52 53 54 55 56 57 |
# File 'lib/trinidad/server.rb', line 51 def ajp_enabled? if ! defined?(@ajp_enabled) || @ajp_enabled.nil? ajp = @config[:ajp] @ajp_enabled = ( !! ajp && ( ! ajp.respond_to?(:empty?) || ! ajp.empty? ) ) end @ajp_enabled end |
#configure(config = Trinidad.configuration) ⇒ Object
12 13 14 15 |
# File 'lib/trinidad/server.rb', line 12 def configure(config = Trinidad.configuration) configure_logging config[:logging] || config[:log] @config = config.freeze end |
#deploy_web_apps(tomcat = self.tomcat) ⇒ Object
248 249 250 251 252 |
# File 'lib/trinidad/server.rb', line 248 def deploy_web_apps(tomcat = self.tomcat) web_apps = create_web_apps add_host_monitor web_apps web_apps end |
#http_configured=(flag) ⇒ Object
Deprecated.
68 |
# File 'lib/trinidad/server.rb', line 68 def http_configured=(flag); @http_configured = flag end |
#http_configured? ⇒ Boolean
60 61 62 63 64 65 66 |
# File 'lib/trinidad/server.rb', line 60 def http_configured? if ! defined?(@http_configured) || @http_configured.nil? http = @config[:http] @http_configured = ( !! http && ( ! http.respond_to?(:empty?) || ! http.empty? ) ) end @http_configured end |
#load_config(config) ⇒ Object
Deprecated.
replaced with #configure
17 |
# File 'lib/trinidad/server.rb', line 17 def load_config(config); configure(config); end |
#load_host_monitor(web_apps) ⇒ Object
Deprecated.
replaced with #setup_host_monitor
123 |
# File 'lib/trinidad/server.rb', line 123 def load_host_monitor(web_apps); add_host_monitor(web_apps); end |
#load_tomcat_server ⇒ Object
#deprecated renamed to #initialize_tomcat
113 |
# File 'lib/trinidad/server.rb', line 113 def load_tomcat_server; initialize_tomcat; end |
#ssl_enabled? ⇒ Boolean Also known as: https_enabled?
40 41 42 43 44 45 46 |
# File 'lib/trinidad/server.rb', line 40 def ssl_enabled? if ! defined?(@ssl_enabled) || @ssl_enabled.nil? ssl = @config.key?(:https) ? @config[:https] : @config[:ssl] @ssl_enabled = ( !! ssl && ( ! ssl.respond_to?(:empty?) || ! ssl.empty? ) ) end @ssl_enabled end |
#start ⇒ Object
254 255 256 257 258 259 260 261 |
# File 'lib/trinidad/server.rb', line 254 def start deploy_web_apps(tomcat) trap_signals if trap? tomcat.start tomcat.server.await end |
#start! ⇒ Object
263 264 265 266 267 268 |
# File 'lib/trinidad/server.rb', line 263 def start! if defined?(@tomcat) && @tomcat @tomcat.destroy; @tomcat = nil end start end |
#stop ⇒ Object
270 271 272 273 274 |
# File 'lib/trinidad/server.rb', line 270 def stop if defined?(@tomcat) && @tomcat @tomcat.stop; true end end |
#stop! ⇒ Object
276 277 278 |
# File 'lib/trinidad/server.rb', line 276 def stop! (@tomcat.destroy; true) if stop end |
#tomcat ⇒ Object
70 |
# File 'lib/trinidad/server.rb', line 70 def tomcat; @tomcat ||= initialize_tomcat; end |
#trap? ⇒ Boolean
34 35 36 37 |
# File 'lib/trinidad/server.rb', line 34 def trap? @trap = !! @config[:trap] if ! defined?(@trap) || @trap.nil? @trap end |