upstart-unicorn-launcher 0.0.3 → 0.0.4

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: fcfcecdaacbb99d28cb3ba75e37e0f2f77aa7180
4
- data.tar.gz: 7f9384d07859a01267cfc0e3e00b10e2825aa10e
3
+ metadata.gz: 81675d74f21b08aa061a2ce4beaed5b6c9370961
4
+ data.tar.gz: acc2ca0094d53dcd461f0dd9f39bd259b10b344a
5
5
  SHA512:
6
- metadata.gz: 264cfee8d9ba752f70a878de25dbcd19716c1dfd858dbb66832e9bdc00f6857432719edf9b00320e78918897e0a1b5e66258dd6bf109aba88bc389b3a6de4b30
7
- data.tar.gz: 599e9ce3cc01913b01b96ea04e3dfefba648662aba7aaa2f3625c1044effaa58a4e0c4a14801f00abe48d411af274ddfba06493f774f414aff678bce4638e5f4
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
- wait_until_server_quits
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
- wait_for { File.exist?(pidfile) }
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.each do |signal|
36
- debug "Received #{signal}, restarting server"
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.each do |signal|
43
- trap(signal.to_s) do
44
- debug "Received #{signal}, quitting server"
45
- Process.kill signal.to_s, pid
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.each do |signal|
54
- trap(signal.to_s) do
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
- wait_for { !running? }
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(timeout = 20, &block)
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
- until block.call
111
- sleep tick_period
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
@@ -1,3 +1,3 @@
1
1
  class UpstartUnicornLauncher
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,4 +1,4 @@
1
- module ProjectSupport
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
- config.include ProjectSupport
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: upstart-unicorn-launcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Ward