Skip to content

Commit d67ae56

Browse files
committed
unicorn as server
1 parent 3f340b8 commit d67ae56

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
22
ruby '2.0.0'
33

44
group :heroku do
5-
gem 'thin'
5+
gem 'unicorn'
66
gem 'rails_12factor'
77
end
88

Gemfile.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ GEM
3636
carrierwave (0.6.1)
3737
activemodel (>= 3.2.0)
3838
activesupport (>= 3.2.0)
39-
daemons (1.1.9)
4039
erubis (2.7.0)
41-
eventmachine (1.0.0)
4240
excon (0.13.4)
4341
faraday (0.8.8)
4442
multipart-post (~> 1.2.0)
@@ -61,6 +59,7 @@ GEM
6159
json (1.8.0)
6260
jwt (0.1.8)
6361
multi_json (>= 1.5)
62+
kgio (2.8.1)
6463
mail (2.5.4)
6564
mime-types (~> 1.16)
6665
treetop (~> 1.4.8)
@@ -119,6 +118,7 @@ GEM
119118
rake (>= 0.8.7)
120119
rdoc (~> 3.4)
121120
thor (>= 0.14.6, < 2.0)
121+
raindrops (0.12.0)
122122
rake (10.1.0)
123123
rdoc (3.12.2)
124124
json (~> 1.4)
@@ -132,16 +132,16 @@ GEM
132132
sqlite3-ruby (1.3.3)
133133
sqlite3 (>= 1.3.3)
134134
subexec (0.2.2)
135-
thin (1.5.0)
136-
daemons (>= 1.0.9)
137-
eventmachine (>= 0.12.6)
138-
rack (>= 1.0.0)
139135
thor (0.18.1)
140136
tilt (1.4.1)
141137
treetop (1.4.15)
142138
polyglot
143139
polyglot (>= 0.3.1)
144140
tzinfo (0.3.37)
141+
unicorn (4.6.3)
142+
kgio (~> 2.6)
143+
rack
144+
raindrops (~> 0.7)
145145

146146
PLATFORMS
147147
ruby
@@ -159,4 +159,4 @@ DEPENDENCIES
159159
rails (= 3.2.14)
160160
rails_12factor
161161
sqlite3-ruby
162-
thin
162+
unicorn

Procfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
web: bundle exec thin start -p $PORT -e $RACK_ENV
1+
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

config/unicorn.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
2+
timeout 15
3+
preload_app true
4+
5+
before_fork do |server, worker|
6+
Signal.trap 'TERM' do
7+
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
8+
Process.kill 'QUIT', Process.pid
9+
end
10+
11+
defined?(ActiveRecord::Base) and
12+
ActiveRecord::Base.connection.disconnect!
13+
end
14+
15+
after_fork do |server, worker|
16+
Signal.trap 'TERM' do
17+
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
18+
end
19+
20+
defined?(ActiveRecord::Base) and
21+
ActiveRecord::Base.establish_connection
22+
end

0 commit comments

Comments
 (0)