upstart-unicorn-launcher 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/upstart_unicorn_launcher.rb +30 -21
- data/lib/upstart_unicorn_launcher/version.rb +1 -1
- data/spec/spec_helper.rb +5 -4
- data/spec/upstart_integration_spec.rb +6 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 81675d74f21b08aa061a2ce4beaed5b6c9370961
|
4
|
+
data.tar.gz: acc2ca0094d53dcd461f0dd9f39bd259b10b344a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8fb5f6084e831a664202ea5dc0a61620ad054c928c601a9b192dffe0631e7720ee7c983a86c71f86ed5027a47ea782405ad51fb4891c7017a20acfc3b5d6e799
|
7
|
+
data.tar.gz: 3aa5c4869908646138cc1781606b99210cd9e6b2bcd7816e760ea5ef47dc170d3294d566f0470e52b92f64197f08d864e37c651c78acc160ce80c1828db6d72f
|
@@ -17,7 +17,9 @@ class UpstartUnicornLauncher
|
|
17
17
|
quit_server_on :QUIT, :INT, :TERM
|
18
18
|
forward_to_server :USR1, :USR2, :WINCH, :TTIN, :TTOU
|
19
19
|
start_server
|
20
|
-
|
20
|
+
loop do
|
21
|
+
sleep 1
|
22
|
+
end
|
21
23
|
end
|
22
24
|
|
23
25
|
private
|
@@ -25,45 +27,39 @@ class UpstartUnicornLauncher
|
|
25
27
|
def start_server
|
26
28
|
abort "The unicorn pidfile '#{pidfile}' already exists. Is the server running already?" if File.exist?(pidfile)
|
27
29
|
spawned_pid = Process.spawn command
|
28
|
-
|
30
|
+
wait_for_with_timeout { File.exist?(pidfile) }
|
29
31
|
rescue Timeout::Error
|
30
32
|
Process.kill "QUIT", spawned_pid
|
31
33
|
abort "Unable to find server running with pidfile #{pidfile}. Exiting"
|
32
34
|
end
|
33
35
|
|
34
36
|
def restart_server_on(*signals)
|
35
|
-
signals
|
36
|
-
|
37
|
-
trap(signal.to_s) { restart_server }
|
37
|
+
trap_signals("restarting server", *signals) do
|
38
|
+
restart_server
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
41
42
|
def quit_server_on(*signals)
|
42
|
-
signals
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
wait_until_server_quits
|
47
|
-
exit
|
48
|
-
end
|
43
|
+
trap_signals("quitting server", *signals) do |signal|
|
44
|
+
Process.kill signal, pid
|
45
|
+
wait_until_server_quits
|
46
|
+
exit
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
52
50
|
def forward_to_server(*signals)
|
53
|
-
signals
|
54
|
-
|
55
|
-
debug "Forwarding #{signal} to #{pid}"
|
56
|
-
Process.kill signal.to_s, pid
|
57
|
-
end
|
51
|
+
trap_signals("forwarding", *signals) do |signal|
|
52
|
+
Process.kill signal, pid
|
58
53
|
end
|
59
54
|
end
|
60
55
|
|
61
56
|
def wait_until_server_quits
|
62
|
-
|
57
|
+
wait_for_with_timeout { !running? }
|
63
58
|
end
|
64
59
|
|
65
60
|
def restart_server
|
66
61
|
reexecute_running_binary
|
62
|
+
wait_for_with_timeout { old_pid }
|
67
63
|
wait_for_server_to_start
|
68
64
|
quit_old_master
|
69
65
|
end
|
@@ -105,10 +101,23 @@ class UpstartUnicornLauncher
|
|
105
101
|
end
|
106
102
|
end
|
107
103
|
|
108
|
-
def wait_for(
|
104
|
+
def wait_for(&block)
|
105
|
+
until block.call
|
106
|
+
sleep tick_period
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def wait_for_with_timeout(timeout = 20, &block)
|
109
111
|
Timeout::timeout timeout do
|
110
|
-
|
111
|
-
|
112
|
+
wait_for(&block)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def trap_signals(message, *signals, &block)
|
117
|
+
signals.map(&:to_s).each do |signal|
|
118
|
+
trap(signal) do
|
119
|
+
debug "Received #{signal}, #{message}"
|
120
|
+
block.call signal
|
112
121
|
end
|
113
122
|
end
|
114
123
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module SpecHelper
|
2
2
|
def perform_request
|
3
3
|
response = Curl::Easy.perform('http://localhost:7516')
|
4
4
|
end
|
@@ -17,8 +17,9 @@ module ProjectSupport
|
|
17
17
|
puts "Killing #{@launcher_pid}"
|
18
18
|
Process.kill "QUIT", @launcher_pid
|
19
19
|
end
|
20
|
-
end
|
21
20
|
|
22
|
-
RSpec.configure do |config|
|
23
|
-
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.include self
|
23
|
+
end
|
24
24
|
end
|
25
|
+
|
@@ -6,6 +6,12 @@ describe 'Upstart integration' do
|
|
6
6
|
kill_launcher
|
7
7
|
end
|
8
8
|
|
9
|
+
after :all do
|
10
|
+
if File.exist?('spec/templates/test/unicorn.pid')
|
11
|
+
Process.kill "QUIT", File.read('spec/templates/test/unicorn.pid').to_i
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
9
15
|
it 'starts server' do
|
10
16
|
start_launcher
|
11
17
|
expect {perform_request}.to_not raise_error
|