upstart-unicorn-launcher 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/upstart_unicorn_launcher/version.rb +1 -1
- data/lib/upstart_unicorn_launcher.rb +16 -10
- 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: a414fcb8c1871445b2111e954bdc9cb65850a44d
|
4
|
+
data.tar.gz: 60ede7fcda9a76782338b223bfdab17546231b39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f783ab849e8a605392a3cd5eb1fdb175ddddcc81f7a00ff87c90092f180a687ddf7a706aa7968b13dc4cb052304b044932c3d65d0e610ed8ba9dc6ef4ad987e1
|
7
|
+
data.tar.gz: c60199146b50352e229c438ce300e1533d3ffa162b8eb1d58b558487122e1af9c0641b7cfce0c518f6e169e5475fd9d97bdb5c50a1359db33431a54ebbbccdf8
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'timeout'
|
2
2
|
|
3
3
|
class UpstartUnicornLauncher
|
4
4
|
attr_accessor :command, :pidfile, :startup_period, :tick_period, :restarting
|
@@ -7,7 +7,7 @@ class UpstartUnicornLauncher
|
|
7
7
|
self.command = command
|
8
8
|
self.pidfile = File.expand_path(options[:pidfile] || 'unicorn.pid')
|
9
9
|
self.startup_period = options[:startup] || 60
|
10
|
-
self.tick_period = options[:tick] || 1
|
10
|
+
self.tick_period = options[:tick] || 0.1
|
11
11
|
end
|
12
12
|
|
13
13
|
def start
|
@@ -24,11 +24,10 @@ class UpstartUnicornLauncher
|
|
24
24
|
def start_server
|
25
25
|
abort "The unicorn pidfile '#{pidfile}' already exists. Is the server running already?" if File.exist?(pidfile)
|
26
26
|
spawned_pid = Process.spawn command
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
27
|
+
wait_for { File.exist?(pidfile) }
|
28
|
+
rescue Timeout::Error
|
29
|
+
Process.kill "QUIT", spawned_pid
|
30
|
+
abort "Unable to find server running with pidfile #{pidfile}. Exiting"
|
32
31
|
end
|
33
32
|
|
34
33
|
def restart_server_on(*signals)
|
@@ -41,6 +40,7 @@ class UpstartUnicornLauncher
|
|
41
40
|
signals.each do |signal|
|
42
41
|
trap(signal.to_s) do
|
43
42
|
Process.kill signal.to_s, pid
|
43
|
+
wait_until_server_quits
|
44
44
|
exit
|
45
45
|
end
|
46
46
|
end
|
@@ -56,9 +56,7 @@ class UpstartUnicornLauncher
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def wait_until_server_quits
|
59
|
-
|
60
|
-
sleep tick_period
|
61
|
-
end
|
59
|
+
wait_for { !running? }
|
62
60
|
end
|
63
61
|
|
64
62
|
def restart_server
|
@@ -101,4 +99,12 @@ class UpstartUnicornLauncher
|
|
101
99
|
def debug(message)
|
102
100
|
puts message
|
103
101
|
end
|
102
|
+
|
103
|
+
def wait_for(timeout = 20, &block)
|
104
|
+
Timeout::timeout timeout do
|
105
|
+
until block.call
|
106
|
+
sleep tick_period
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
104
110
|
end
|