Skip to content

Commit

Permalink
Use SSL and Unicorn in production
Browse files Browse the repository at this point in the history
  • Loading branch information
bodfarian committed Nov 1, 2014
1 parent 090e66c commit 75dae5f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://rubygems.org'
ruby '2.1.1'

gem 'rails', '4.2.0.beta2'
gem 'bcrypt', '3.1.7'
Expand Down Expand Up @@ -29,4 +30,5 @@ end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'unicorn', '4.8.3'
end
7 changes: 7 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ GEM
railties (>= 4.2.0.beta, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
kgio (2.9.2)
listen (2.7.11)
celluloid (>= 0.15.2)
rb-fsevent (>= 0.9.3)
Expand Down Expand Up @@ -148,6 +149,7 @@ GEM
activesupport (= 4.2.0.beta2)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
raindrops (0.13.0)
rake (10.3.2)
rb-fsevent (0.9.4)
rb-inotify (0.9.5)
Expand Down Expand Up @@ -188,6 +190,10 @@ GEM
uglifier (2.5.3)
execjs (>= 0.3.0)
json (>= 1.8.0)
unicorn (4.8.3)
kgio (~> 2.6)
rack
raindrops (~> 0.7)
web-console (2.0.0.beta3)
activemodel (~> 4.0)
binding_of_caller (= 0.7.3.pre1)
Expand Down Expand Up @@ -217,4 +223,5 @@ DEPENDENCIES
sqlite3 (= 1.3.9)
turbolinks (= 2.3.0)
uglifier (= 2.5.3)
unicorn (= 4.8.3)
web-console (= 2.0.0.beta3)
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX

# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
# config.force_ssl = true
config.force_ssl = true

# Decrease the log volume.
# config.log_level = :info
Expand Down
22 changes: 22 additions & 0 deletions config/unicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
timeout 15
preload_app true

before_fork do |server, worker|
Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
Process.kill 'QUIT', Process.pid
end

defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|
Signal.trap 'TERM' do
msg = 'Unicorn worker intercepting TERM and doing nothing. '
msg += 'Wait for master to send QUIT'
puts msg
end

defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
end

0 comments on commit 75dae5f

Please sign in to comment.