diff --git a/build b/build index ddf6f3cf1..5843ec89f 100755 --- a/build +++ b/build @@ -63,6 +63,7 @@ if [ -n "$PACKAGE" ]; then echo "BUILD NUMBER is not defined" exit 1 fi + set -e # cache all gems local, and tell bundle to use local gems only bundle install --path vendor/bundle --local # prepare production acssets diff --git a/config/environments/production.rb b/config/environments/production.rb index b9bc1648d..76e7584df 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -20,6 +20,8 @@ SampleApp::Application.configure do # Generate digests for assets URLs config.assets.digest = true + config.assets.initialize_on_precompile = false + # Defaults to Rails.root.join("public/assets") # config.assets.manifest = YOUR_PATH @@ -31,7 +33,7 @@ SampleApp::Application.configure do config.force_ssl = false # See everything in the log (default is :info) - # config.log_level = :debug + config.log_level = :debug # Prepend all log lines with the following tags # config.log_tags = [ :subdomain, :uuid ] @@ -70,4 +72,7 @@ SampleApp::Application.configure do # Show the logging configuration on STDOUT config.show_log_configuration = true + + # run websocket-gateway embedded + config.websocket_gateway_enable = false end diff --git a/config/initializers/eventmachine.rb b/config/initializers/eventmachine.rb index 34b964974..fc93d5352 100644 --- a/config/initializers/eventmachine.rb +++ b/config/initializers/eventmachine.rb @@ -10,13 +10,7 @@ require 'jam_ruby' module JamWebEventMachine - def self.start - - Thread.abort_on_exception = true - - # create a new thread separate from the Rails main thread that EventMachine can run on - Thread.new do - + def self.run_em EM.run do AMQP.start(:host => Rails.application.config.rabbitmq_host, :port => Rails.application.config.rabbitmq_port) do |connection| AMQP::Channel.new do |channel, open_ok| @@ -33,9 +27,40 @@ module JamWebEventMachine end end end + end + end + + def self.die_gracefully_on_signal + Signal.trap("INT") { EM.stop } + Signal.trap("TERM") { EM.stop } + end + + def self.start + if defined?(PhusionPassenger) + Rails.logger.debug("PhusionPassenger detected") + + PhusionPassenger.on_event(:starting_worker_process) do |forked| + # for passenger, we need to avoid orphaned threads + if forked && EM.reactor_running? + Rails.logger.debug("stopping EventMachine") + EM.stop + end + Rails.logger.debug("starting EventMachine") + Thread.new { + run_em + } + die_gracefully_on_signal + end + else + Rails.logger.debug("PhusionPassenger not detected") + Thread.abort_on_exception = true + + # create a new thread separate from the Rails main thread that EventMachine can run on + Thread.new do + run_em end end end end -JamWebEventMachine.start \ No newline at end of file +JamWebEventMachine.start