diff --git a/Gemfile b/Gemfile index 629ab6a..bdf5c1e 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'sqlite3' gem 'omniauth-twitter' gem 'twitter' gem 'twitter-text' +gem 'foreman' # Gems used only for assets and not required # in production environments by default. @@ -65,4 +66,5 @@ end group :production do gem "mysql2" + gem "unicorn" end diff --git a/Gemfile.lock b/Gemfile.lock index ef76268..da5ae17 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -61,6 +61,8 @@ GEM faraday (0.8.1) multipart-post (~> 1.1) ffi (1.1.0) + foreman (0.47.0) + thor (>= 0.13.6) git-deploy (0.5.4) net-scp net-ssh @@ -82,6 +84,7 @@ GEM railties (>= 3.2.0, < 5.0) thor (~> 0.14) json (1.7.4) + kgio (2.7.4) less (2.2.1) commonjs (~> 0.2.6) less-rails (2.2.3) @@ -139,6 +142,7 @@ GEM rake (>= 0.8.7) rdoc (~> 3.4) thor (~> 0.14.6) + raindrops (0.10.0) rake (0.9.2.2) rb-fchange (0.0.5) ffi @@ -200,6 +204,10 @@ GEM uglifier (1.2.6) execjs (>= 0.3.0) multi_json (~> 1.3) + unicorn (4.3.1) + kgio (~> 2.6) + rack + raindrops (~> 0.7) xpath (0.1.4) nokogiri (~> 1.3) @@ -211,6 +219,7 @@ DEPENDENCIES coffee-rails (~> 3.2.1) database_cleaner factory_girl_rails + foreman git-deploy growl guard-rspec @@ -228,3 +237,4 @@ DEPENDENCIES twitter-bootstrap-rails twitter-text uglifier (>= 1.0.3) + unicorn diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..9c82374 --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb diff --git a/config/environments/production.rb b/config/environments/production.rb index 838e9b9..af6fe2b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -12,7 +12,7 @@ config.serve_static_assets = false # Compress JavaScripts and CSS - config.assets.compress = true + config.assets.compress = false # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = false diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 0000000..6092553 --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,19 @@ +worker_processes 3 +timeout 30 +preload_app true + +before_fork do |server, worker| + if defined?(ActiveRecord::Base) + ActiveRecord::Base.connection.disconnect! + Rails.logger.info("Disconnected from ActiveRecord") + end + + sleep 1 +end + +after_fork do |server, worker| + if defined?(ActiveRecord::Base) + ActiveRecord::Base.establish_connection + Rails.logger.info("Connected to ActiveRecord") + end +end diff --git a/deploy/before_restart b/deploy/before_restart index 223ae53..eb176b5 100755 --- a/deploy/before_restart +++ b/deploy/before_restart @@ -49,6 +49,8 @@ if File.file? 'Rakefile' run "#{rake_cmd} #{tasks.join(' ')} RAILS_ENV=#{RAILS_ENV}" if tasks.any? end +run 'bundle exec rake assets:precompile' + # clear cached assets (unversioned/ignored files) run "git clean -x -f -- public/stylesheets public/javascripts" diff --git a/deploy/restart b/deploy/restart index 6094ade..941d1b6 100755 --- a/deploy/restart +++ b/deploy/restart @@ -1,3 +1,4 @@ #!/bin/sh -touch tmp/restart.txt -echo "restarting Passenger app" +sudo /usr/sbin/service lvrug stop +sudo /usr/sbin/service lvrug start +echo "restarting app"