server-starter 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +17 -26
- data/example/config/unicorn.conf +16 -25
- data/lib/server/starter/unicorn_listener.rb +33 -0
- data/lib/server/starter/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f0ef5edbfbb9ba17014f1db7a34876b5b06b687
|
4
|
+
data.tar.gz: 0e38e80a7d760ea3c774f7c677a7f259bf9c7133
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d91568f35236855ce8d0a7a77cefb05ca73543d60af9d241886233a49e1479a13665aea0c7219bfb79ee078f2e207562ce755aad4fffa7eb0a0f8de2cbfcfafc
|
7
|
+
data.tar.gz: 2c8f16573b6cab8c5cc834881b7001c566d47236572b3a0c5c0de731d5d0390a927a62833ddb3ffc33b6d416f5fc2cf0145363f07ebcbfc49d4691adc2e16319
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -32,20 +32,18 @@ bundle exec start_server.rb --status-file=/path/to/app/log/unicorn.stat \
|
|
32
32
|
An example of unicorn.conf:
|
33
33
|
|
34
34
|
```ruby
|
35
|
-
|
35
|
+
require 'server/starter/unicorn_listener'
|
36
|
+
listener = Server::Starter::UnicornListener
|
37
|
+
|
38
|
+
worker_processes 2
|
36
39
|
preload_app true
|
37
40
|
|
38
41
|
APP_ROOT = File.expand_path('../..', __FILE__)
|
39
42
|
status_file = File.join(APP_ROOT, 'log/unicorn.stat')
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
fd
|
45
|
-
}
|
46
|
-
ENV['UNICORN_FD'] = fds.join(',')
|
47
|
-
ENV.delete('SERVER_STARTER_PORT')
|
48
|
-
else
|
43
|
+
|
44
|
+
fd = listener.listen
|
45
|
+
unless fd
|
46
|
+
# Fallback if not running under Server::Starter
|
49
47
|
listen ENV['PORT'] || '10080'
|
50
48
|
end
|
51
49
|
|
@@ -61,22 +59,15 @@ end
|
|
61
59
|
|
62
60
|
after_fork do |server, worker|
|
63
61
|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
if old_pid = pids[old_gen.to_s]
|
74
|
-
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
75
|
-
Process.kill(sig, old_pid.to_i)
|
76
|
-
end
|
77
|
-
rescue Errno::ENOENT, Errno::ESRCH => e
|
78
|
-
$stderr.puts "#{e.class} #{e.message}"
|
79
|
-
end
|
62
|
+
|
63
|
+
# This is optional
|
64
|
+
#
|
65
|
+
# This allows a new master process to incrementally
|
66
|
+
# phase out the old master process with SIGTTOU to avoid a
|
67
|
+
# thundering herd (especially in the "preload_app false" case)
|
68
|
+
# when doing a transparent upgrade. The last worker spawned
|
69
|
+
# will then kill off the old master process with a SIGQUIT.
|
70
|
+
listener.slow_start(server, worker, status_file)
|
80
71
|
end
|
81
72
|
```
|
82
73
|
|
data/example/config/unicorn.conf
CHANGED
@@ -1,17 +1,15 @@
|
|
1
|
+
require 'server/starter/unicorn_listener'
|
2
|
+
listener = Server::Starter::UnicornListener
|
3
|
+
|
1
4
|
worker_processes 2
|
2
5
|
preload_app true
|
3
6
|
|
4
7
|
APP_ROOT = File.expand_path('../..', __FILE__)
|
5
8
|
status_file = File.join(APP_ROOT, 'log/unicorn.stat')
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
fd
|
11
|
-
}
|
12
|
-
ENV['UNICORN_FD'] = fds.join(',')
|
13
|
-
ENV.delete('SERVER_STARTER_PORT')
|
14
|
-
else
|
9
|
+
|
10
|
+
fd = listener.listen
|
11
|
+
unless fd
|
12
|
+
# Fallback if not running under Server::Starter
|
15
13
|
listen ENV['PORT'] || '10080'
|
16
14
|
end
|
17
15
|
|
@@ -27,20 +25,13 @@ end
|
|
27
25
|
|
28
26
|
after_fork do |server, worker|
|
29
27
|
defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
if old_pid = pids[old_gen.to_s]
|
40
|
-
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
41
|
-
Process.kill(sig, old_pid.to_i)
|
42
|
-
end
|
43
|
-
rescue Errno::ENOENT, Errno::ESRCH => e
|
44
|
-
$stderr.puts "#{e.class} #{e.message}"
|
45
|
-
end
|
28
|
+
|
29
|
+
# This is optional
|
30
|
+
#
|
31
|
+
# This allows a new master process to incrementally
|
32
|
+
# phase out the old master process with SIGTTOU to avoid a
|
33
|
+
# thundering herd (especially in the "preload_app false" case)
|
34
|
+
# when doing a transparent upgrade. The last worker spawned
|
35
|
+
# will then kill off the old master process with a SIGQUIT.
|
36
|
+
listener.slow_start(server, worker, status_file)
|
46
37
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Server::Starter
|
2
|
+
class UnicornListener
|
3
|
+
# Map ENV['SERVER_STARTER_PORT'] to ENV['UNICORN_FD']
|
4
|
+
def self.listen
|
5
|
+
return nil unless ENV.key?('SERVER_STARTER_PORT')
|
6
|
+
fds = ENV['SERVER_STARTER_PORT'].split(';').map { |x|
|
7
|
+
path_or_port, fd = x.split('=', 2)
|
8
|
+
fd
|
9
|
+
}
|
10
|
+
ENV['UNICORN_FD'] = fds.join(',')
|
11
|
+
end
|
12
|
+
|
13
|
+
# This allows a new master process to incrementally
|
14
|
+
# phase out the old master process with SIGTTOU to avoid a
|
15
|
+
# thundering herd (especially in the "preload_app false" case)
|
16
|
+
# when doing a transparent upgrade. The last worker spawned
|
17
|
+
# will then kill off the old master process with a SIGQUIT.
|
18
|
+
#
|
19
|
+
# @param server [Unicorn::HttpServer]
|
20
|
+
# @param worker [Unicorn::Worker]
|
21
|
+
# @param status_file [String] path to Server::Starter status file (--status-file)
|
22
|
+
def self.slow_start(server, worker, status_file)
|
23
|
+
pids = File.readlines(status_file).map {|_| _.chomp.split(':') }.to_h
|
24
|
+
old_gen = ENV['SERVER_STARTER_GENERATION'].to_i - 1
|
25
|
+
if old_pid = pids[old_gen.to_s]
|
26
|
+
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
27
|
+
Process.kill(sig, old_pid.to_i)
|
28
|
+
end
|
29
|
+
rescue Errno::ENOENT, Errno::ESRCH => e
|
30
|
+
$stderr.puts "#{e.class} #{e.message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: server-starter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naotoshi Seo
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- example/start_server
|
49
49
|
- lib/server/starter.rb
|
50
50
|
- lib/server/starter/helper.rb
|
51
|
+
- lib/server/starter/unicorn_listener.rb
|
51
52
|
- lib/server/starter/version.rb
|
52
53
|
- server-starter.gemspec
|
53
54
|
homepage: https://github.com/sonots/ruby-server-starter
|