unicorn-wrangler 0.0.2 → 0.0.3

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: 1c453420ee8fd0c8d01dc9226450e39d2223388c
4
- data.tar.gz: 535e8fb3e3c75539a811f396127d3a4b00e78e9b
3
+ metadata.gz: 71bee49e7a7465805c10eee3e28597ed216727b6
4
+ data.tar.gz: f19c67dbc73080d46de86a01a4142868569745ac
5
5
  SHA512:
6
- metadata.gz: b0b31942c67f3e15db8fd0724b5d363cee9f5f2807be1927dea4e84981b04826ff229bbb77dbf08d31746c96ed6603be4f50b5f9eb1b438dccef7e973a920bd3
7
- data.tar.gz: 1e8e6520147bb560d52cc49c415f1beb68188cc6d7269b71e34a7eaa45511168d8d6037d598fb835c8d1e0a94a9c6524f398b3d3ca931b49b564e52661fbeb66
6
+ metadata.gz: 0aa20517db73067e8dbaaa3aadb35c355c3e9f8e5abe2ebdde07c64b6c87cf935893271a43ce5535475de6210bdee98c0b674ca42f8c6677b89948ca76985d35
7
+ data.tar.gz: cf19b3a4c8d5b1861aee2d48356ab0bc1c4af868b3ea1231e2d1b3d3a74e668bcc6fd6e15c27690647b60e6d538d90a65ae8bd444c578da7c523e2cdc4f47457
@@ -11,7 +11,11 @@ module Unicorn
11
11
  end
12
12
 
13
13
  def start
14
- trap_signals(:QUIT, :INT, :TERM) { exit }
14
+ trap_signals(:HUP) { restart_unicorn }
15
+ trap_signals(:QUIT, :INT, :TERM) do |signal|
16
+ Process.kill signal, unicorn_pid if unicorn_running?
17
+ exit
18
+ end
15
19
 
16
20
  if unicorn_running?
17
21
  restart_unicorn
@@ -31,6 +35,7 @@ module Unicorn
31
35
  def trap_signals(*signals, &block)
32
36
  signals.map(&:to_s).each do |signal|
33
37
  trap(signal) do
38
+ puts "unicorn-wrangler #{Process.pid} received #{signal} (managing #{unicorn_pid})"
34
39
  block.call signal
35
40
  end
36
41
  end
@@ -1,5 +1,5 @@
1
1
  module Unicorn
2
2
  class Wrangler
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -54,25 +54,47 @@ describe Unicorn::Wrangler do
54
54
  start_wrangler
55
55
  end
56
56
 
57
- it 'quits (but leaves unicorn running) on receiving QUIT signal' do
57
+ context 'on receiving HUP signal' do
58
+ before do
59
+ @original_pid = unicorn_pid
60
+ @original_response = perform_request
61
+ Process.kill :HUP, @wrangler_pid
62
+ end
63
+
64
+ it 'restarts unicorn on startup' do
65
+ sleep 3
66
+ unicorn_pid.should_not eql(@original_pid)
67
+ end
68
+
69
+ it 'continues serving requests from both unicorns' do
70
+ 20.times.map { sleep 0.1; perform_request }.uniq.size.should eql(2)
71
+ end
72
+
73
+ it 'stops serving requests from original unicorn' do
74
+ sleep 3
75
+ perform_request.should_not eql(@original_response)
76
+ end
77
+ end
78
+
79
+ it 'quits on receiving QUIT signal' do
58
80
  Process.kill 'QUIT', @wrangler_pid
59
81
  sleep 1
60
82
  wrangler_running?.should_not be_true
61
- unicorn_running?.should be_true
83
+ unicorn_running?.should_not be_true
62
84
  end
63
85
 
64
- it 'quits (but leaves unicorn running) on receiving TERM signal' do
86
+ it 'quits on receiving TERM signal' do
65
87
  Process.kill 'TERM', @wrangler_pid
66
88
  sleep 1
67
89
  wrangler_running?.should_not be_true
68
- unicorn_running?.should be_true
90
+ unicorn_running?.should_not be_true
69
91
  end
70
92
 
71
- it 'quits (but leaves unicorn running) on receiving INT signal' do
93
+ it 'quits on receiving INT signal' do
72
94
  Process.kill 'INT', @wrangler_pid
73
95
  sleep 1
74
96
  wrangler_running?.should_not be_true
75
- unicorn_running?.should be_true
97
+ unicorn_running?.should_not be_true
76
98
  end
77
99
 
78
100
  it 'quits if monitored unicorn process quits' do
@@ -81,7 +103,7 @@ describe Unicorn::Wrangler do
81
103
  wrangler_running?.should_not be_true
82
104
  end
83
105
 
84
- it 'continues running after launch (so that process monitoring tools do not restart it)' do
106
+ it 'continues running unless unicorn process quits' do
85
107
  sleep 3
86
108
  wrangler_running?.should be_true
87
109
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicorn-wrangler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Ward