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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d109d9f24ae93e72009230eb434e0a9abcafa2b6
4
- data.tar.gz: 981df7c77180b3896c5bca99157843939b888fff
3
+ metadata.gz: a414fcb8c1871445b2111e954bdc9cb65850a44d
4
+ data.tar.gz: 60ede7fcda9a76782338b223bfdab17546231b39
5
5
  SHA512:
6
- metadata.gz: df7459fba6ab6f0f2c03a54ed0356c47a1116f7d3f21299abbe5b39655f6a48e171c3eafeb1d10b3cd768e7cc32fccb57eefbba5cc9dbd4c615318ff45aaae31
7
- data.tar.gz: 62a444ff416ca8334264e026c333d3454081e01381be722e4ad11b9bebc9a757687f8d1df501563f9f313dbf17983780bc11d58651199a795d452a14cf6b64e6
6
+ metadata.gz: f783ab849e8a605392a3cd5eb1fdb175ddddcc81f7a00ff87c90092f180a687ddf7a706aa7968b13dc4cb052304b044932c3d65d0e610ed8ba9dc6ef4ad987e1
7
+ data.tar.gz: c60199146b50352e229c438ce300e1533d3ffa162b8eb1d58b558487122e1af9c0641b7cfce0c518f6e169e5475fd9d97bdb5c50a1359db33431a54ebbbccdf8
@@ -1,3 +1,3 @@
1
1
  class UpstartUnicornLauncher
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,4 +1,4 @@
1
- require "upstart_unicorn_launcher/version"
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
- sleep 0.5
28
- unless File.exist?(pidfile)
29
- Process.kill "QUIT", spawned_pid
30
- abort "Unable to find server running with pidfile #{pidfile}. Exiting"
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
- while running?
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
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.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Ward