Skip to content

Commit 15e8187

Browse files
author
Jesse Newland
committed
Merge pull request github#484 from github/unicorn
unicorn support
2 parents c11b952 + 5c0b36e commit 15e8187

File tree

10 files changed

+49
-2
lines changed

10 files changed

+49
-2
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ docs/payload_data
1212
.project
1313
.settings
1414
.buildpath
15-
15+
log/*.log

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ gem "right_aws", "3.0.3"
2727
gem "right_http_connection", "1.3.0"
2828
gem "mqtt", "0.0.8"
2929
gem "softlayer_messaging", "~> 1.0.2"
30-
gem "aws-sdk", "1.6.8"
30+
gem "aws-sdk", "1.6.8"
31+
gem "unicorn", "~> 4.5.0"

Gemfile.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ GEM
3636
json (1.6.6)
3737
jwt (0.1.3)
3838
json (>= 1.2.4)
39+
kgio (2.7.4)
3940
mail (2.3.0)
4041
i18n (>= 0.4.0)
4142
mime-types (~> 1.16)
@@ -51,6 +52,7 @@ GEM
5152
rack (1.4.1)
5253
rack-test (0.6.1)
5354
rack (>= 1.0)
55+
raindrops (0.10.0)
5456
rake (0.8.7)
5557
rest-client (1.6.7)
5658
mime-types (>= 1.16)
@@ -92,6 +94,10 @@ GEM
9294
eventmachine (>= 0.12.8)
9395
http_parser.rb (~> 0.5.1)
9496
simple_oauth (~> 0.1.4)
97+
unicorn (4.5.0)
98+
kgio (~> 2.6)
99+
rack
100+
raindrops (~> 0.7)
95101
uuidtools (2.1.3)
96102
xml-simple (1.0.11)
97103
xmpp4r (0.5)
@@ -127,6 +133,7 @@ DEPENDENCIES
127133
tilt (~> 1.2.1)
128134
tinder (= 1.8.0.github)
129135
twilio-ruby (= 3.4.2)
136+
unicorn (~> 4.5.0)
130137
xml-simple (= 1.0.11)
131138
xmpp4r-simple (= 0.8.8)
132139
yajl-ruby (= 1.1.0)

config/unicorn.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
base = "#{File.dirname(__FILE__)}/../"
2+
preload_app true
3+
4+
worker_processes ENV['UNICORN_WORKERS'] ? ENV['UNICORN_WORKERS'].to_i : 1
5+
timeout ENV['UNICORN_TIMEOUT'] ? ENV['UNICORN_TIMEOUT'].to_i : 15
6+
listen ENV['UNICORN_LISTEN'] ? ENV['UNICORN_LISTEN'] : '0.0.0.0:4000'
7+
8+
stderr_path "#{base}/log/unicorn.stderr.log"
9+
stderr_path "#{base}/log/unicorn.stderr.log"
10+
pidfile = "#{base}/tmp/pids/unicorn.pid"
11+
pid pidfile
12+
13+
##
14+
# Signal handling
15+
16+
# Called in the master before forking each worker process.
17+
before_fork do |server, worker|
18+
##
19+
# When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
20+
# immediately start loading up a new version of itself (loaded with a new
21+
# version of our app). When this new Unicorn is completely loaded
22+
# it will begin spawning workers. The first worker spawned will check to
23+
# see if an .oldbin pidfile exists. If so, this means we've just booted up
24+
# a new Unicorn and need to tell the old one that it can now die. To do so
25+
# we send it a QUIT.
26+
#
27+
# Using this method we get 0 downtime deploys.
28+
29+
# wait until last worker boots to send QUIT signal
30+
next if worker.nr != (server.worker_processes - 1)
31+
32+
if File.exists?("#{pidfile}.oldbin") && server.pid != "#{pidfile}.oldbin"
33+
begin
34+
Process.kill("QUIT", File.read("#{pidfile}.oldbin").to_i)
35+
rescue Errno::ENOENT, Errno::ESRCH
36+
# someone else did our job for us
37+
end
38+
end
39+
end

log/.gitkeep

Whitespace-only changes.

tmp/pids/.gitkeep

Whitespace-only changes.

tmp/sockets/.gitkeep

Whitespace-only changes.

vendor/cache/kgio-2.7.4.gem

69.5 KB
Binary file not shown.

vendor/cache/raindrops-0.10.0.gem

72.5 KB
Binary file not shown.

vendor/cache/unicorn-4.5.0.gem

249 KB
Binary file not shown.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy