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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb60fbb2e08b91127b6efbfba149c02ef9e004ec
4
- data.tar.gz: 59d7bd41e7344bd76e08694ec8058c7e14663d91
3
+ metadata.gz: 07223bd2cd439dbd81d9e6c7682dbef99d13af05
4
+ data.tar.gz: c75917973a88533513a353c7f548095c02071f1d
5
5
  SHA512:
6
- metadata.gz: be04b0fce682d909b425db984789f224fb75b8ff8767268a60de2ac1c4775c39e37d5d36a749b058451a8de9dd4146c7ea4742ab56c0c972c375935b17962707
7
- data.tar.gz: 61d6841bbfe9997c9a3578bd405a3e7e42033b8f724f05f4a5614d94d257329b8229568f5320b65fbccea128e70fc230625a18c313c3c12f94ecc793544d1412
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("-s", "--startup-time STARTUP", "Time to wait for server to start") do |time|
17
- options[:startup] = time.to_i
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
 
@@ -2,19 +2,18 @@ require "unicorn/wrangler/version"
2
2
 
3
3
  module Unicorn
4
4
  class Wrangler
5
- attr_reader :command, :pidfile, :startup_period, :tick_period, :verbose
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
- @startup_period = options[:startup] || 60
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
- Process.kill signal, unicorn_pid if unicorn_running? && !@keep_unicorn
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 startup_period
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
@@ -1,5 +1,5 @@
1
1
  module Unicorn
2
2
  class Wrangler
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  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} --startup-time 1 #{extra} -p spec/support/unicorn.pid -- #{unicorn_cmd}"
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 'quits on receiving QUIT signal' do
79
+ it 'exits on receiving QUIT signal' do
80
80
  Process.kill 'QUIT', @wrangler_pid
81
- sleep 1
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 'quits on receiving TERM signal' do
86
+ it 'exits on receiving TERM signal' do
87
87
  Process.kill 'TERM', @wrangler_pid
88
- sleep 1
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 'quits on receiving INT signal' do
93
+ it 'exits on receiving INT signal' do
94
94
  Process.kill 'INT', @wrangler_pid
95
- sleep 1
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
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-13 00:00:00.000000000 Z
11
+ date: 2013-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler