unicorn-wrangler 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/unicorn-wrangler +2 -6
- data/lib/unicorn/wrangler.rb +15 -5
- data/lib/unicorn/wrangler/version.rb +1 -1
- data/spec/lib/unicorn/wrangler_spec.rb +7 -34
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07223bd2cd439dbd81d9e6c7682dbef99d13af05
|
4
|
+
data.tar.gz: c75917973a88533513a353c7f548095c02071f1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66ae9fced46e50425249002ed43216eded8ccc76c40174b20e70ccfe70b3c7f10d0fac5d470f8d653314d1ae11550695a73f10b6c14222d9bbe60f26cc6fc301
|
7
|
+
data.tar.gz: 8ac25f925bcb4b6c01a3f6ac4827e693c1df510972f2ecc20910098f31e18e88e801589a5b5b454316a307c2ab68d3cd7cdf0e21d5d551c888ee58592e47934e
|
data/bin/unicorn-wrangler
CHANGED
@@ -13,12 +13,8 @@ OptionParser.new do |opts|
|
|
13
13
|
options[:pidfile] = pidfile
|
14
14
|
end
|
15
15
|
|
16
|
-
opts.on("-
|
17
|
-
options[:
|
18
|
-
end
|
19
|
-
|
20
|
-
opts.on("-k", "--keep-unicorn-running", "Keep unicorn running on exit") do
|
21
|
-
options[:keep_unicorn] = true
|
16
|
+
opts.on("-g", "--grace-period PERIOD", "Time to wait before shutting down server") do |time|
|
17
|
+
options[:grace_period] = time.to_i
|
22
18
|
end
|
23
19
|
end.parse!(ARGV[0...command_index])
|
24
20
|
|
data/lib/unicorn/wrangler.rb
CHANGED
@@ -2,19 +2,18 @@ require "unicorn/wrangler/version"
|
|
2
2
|
|
3
3
|
module Unicorn
|
4
4
|
class Wrangler
|
5
|
-
attr_reader :command, :pidfile, :
|
5
|
+
attr_reader :command, :pidfile, :grace_period
|
6
6
|
|
7
7
|
def initialize(command, options = {})
|
8
8
|
@command = command
|
9
9
|
@pidfile = File.expand_path(options[:pidfile] || 'unicorn.pid')
|
10
|
-
@
|
11
|
-
@keep_unicorn = options[:keep_unicorn]
|
10
|
+
@grace_period = options[:grace_period] || 60
|
12
11
|
end
|
13
12
|
|
14
13
|
def start
|
15
14
|
trap_signals(:HUP) { restart_unicorn }
|
16
15
|
trap_signals(:QUIT, :INT, :TERM) do |signal|
|
17
|
-
|
16
|
+
kill_unicorn_after_delay
|
18
17
|
exit
|
19
18
|
end
|
20
19
|
|
@@ -46,7 +45,7 @@ module Unicorn
|
|
46
45
|
original_pid = unicorn_pid
|
47
46
|
Process.kill "USR2", unicorn_pid
|
48
47
|
wait_for { unicorn_pid != original_pid }
|
49
|
-
sleep
|
48
|
+
sleep grace_period
|
50
49
|
Process.kill "TERM", original_pid
|
51
50
|
end
|
52
51
|
|
@@ -65,5 +64,16 @@ module Unicorn
|
|
65
64
|
sleep 0.1
|
66
65
|
end
|
67
66
|
end
|
67
|
+
|
68
|
+
def kill_unicorn_after_delay
|
69
|
+
if unicorn_running?
|
70
|
+
puts "Preparing to kill unicorn in #{grace_period} seconds"
|
71
|
+
unless fork
|
72
|
+
Process.setsid
|
73
|
+
sleep grace_period
|
74
|
+
Process.kill :TERM, unicorn_pid if unicorn_running?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
68
78
|
end
|
69
79
|
end
|
@@ -19,7 +19,7 @@ describe Unicorn::Wrangler do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def start_wrangler(extra = '')
|
22
|
-
@wrangler_pid = Process.spawn "#{wrangler_path} --
|
22
|
+
@wrangler_pid = Process.spawn "#{wrangler_path} --grace-period 1 -p spec/support/unicorn.pid -- #{unicorn_cmd}"
|
23
23
|
sleep 1
|
24
24
|
end
|
25
25
|
|
@@ -76,23 +76,23 @@ describe Unicorn::Wrangler do
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
79
|
-
it '
|
79
|
+
it 'exits on receiving QUIT signal' do
|
80
80
|
Process.kill 'QUIT', @wrangler_pid
|
81
|
-
sleep
|
81
|
+
sleep 2
|
82
82
|
wrangler_running?.should_not be_true
|
83
83
|
unicorn_running?.should_not be_true
|
84
84
|
end
|
85
85
|
|
86
|
-
it '
|
86
|
+
it 'exits on receiving TERM signal' do
|
87
87
|
Process.kill 'TERM', @wrangler_pid
|
88
|
-
sleep
|
88
|
+
sleep 2
|
89
89
|
wrangler_running?.should_not be_true
|
90
90
|
unicorn_running?.should_not be_true
|
91
91
|
end
|
92
92
|
|
93
|
-
it '
|
93
|
+
it 'exits on receiving INT signal' do
|
94
94
|
Process.kill 'INT', @wrangler_pid
|
95
|
-
sleep
|
95
|
+
sleep 2
|
96
96
|
wrangler_running?.should_not be_true
|
97
97
|
unicorn_running?.should_not be_true
|
98
98
|
end
|
@@ -146,33 +146,6 @@ describe Unicorn::Wrangler do
|
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
149
|
-
context 'when passed the --keep-unicorn flag' do
|
150
|
-
before :each do
|
151
|
-
start_wrangler '--keep-unicorn'
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'keeps unicorn running after receiving QUIT signal' do
|
155
|
-
Process.kill 'QUIT', @wrangler_pid
|
156
|
-
sleep 1
|
157
|
-
wrangler_running?.should_not be_true
|
158
|
-
unicorn_running?.should be_true
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'keeps unicorn running after receiving TERM signal' do
|
162
|
-
Process.kill 'TERM', @wrangler_pid
|
163
|
-
sleep 1
|
164
|
-
wrangler_running?.should_not be_true
|
165
|
-
unicorn_running?.should be_true
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'keeps unicorn running after receiving INT signal' do
|
169
|
-
Process.kill 'INT', @wrangler_pid
|
170
|
-
sleep 1
|
171
|
-
wrangler_running?.should_not be_true
|
172
|
-
unicorn_running?.should be_true
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
149
|
before :each do
|
177
150
|
cleanup_processes
|
178
151
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unicorn-wrangler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Ward
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|