luban-rack 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/lib/luban/deployment/applications/rack/base.rb +2 -2
- data/lib/luban/deployment/applications/rack/configurator.rb +5 -1
- data/lib/luban/deployment/applications/rack/controller.rb +1 -2
- data/lib/luban/deployment/applications/rack/paths.rb +13 -34
- data/lib/luban/deployment/applications/rack/templates/puma/puma.logrotate.erb +14 -0
- data/lib/luban/deployment/applications/rack/templates/puma/puma.monitrc.erb +17 -0
- data/lib/luban/deployment/applications/rack/templates/puma/puma.nginx.http.proxy.conf.erb +41 -0
- data/lib/luban/deployment/applications/rack/templates/puma/puma.rb.erb +5 -0
- data/lib/luban/deployment/applications/rack/templates/thin/thin.monitrc.erb +3 -3
- data/lib/luban/deployment/applications/rack/templates/thin/{nginx.http.proxy.conf.erb → thin.nginx.http.proxy.conf.erb} +3 -3
- data/lib/luban/deployment/applications/rack/templates/thin/thin.yml.erb +2 -0
- data/lib/luban/deployment/applications/rack/version.rb +1 -1
- data/lib/luban/deployment/applications/rack/web_server.rb +13 -3
- data/lib/luban/deployment/applications/rack/web_servers/puma.rb +157 -0
- data/lib/luban/deployment/applications/rack/web_servers/thin.rb +89 -9
- data/luban-rack.gemspec +1 -1
- metadata +10 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1cc2a9b8d82a3f7b19a886d7764abf720f68af5a
|
4
|
+
data.tar.gz: 5c0d00834f557af998d748aca309b7833861243e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28e1eddb36d0e8905fa6809efa5d688febe92f0c203b22fe87d79c7879019622dfcf77d830b536314c3984636401b5f170cfd270020d692d288f5025072a456b
|
7
|
+
data.tar.gz: e45cfdbe7242f157b8928929a5da609104fd55fe1323584ee2b0629615291da3c0935253b1c118b052ebb263cfe616979e3162cf55a4d2e00543a22979385283
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## Version 0.2.0 (Aug 02, 2016)
|
4
|
+
|
5
|
+
New features:
|
6
|
+
* Supported Puma as web server option
|
7
|
+
* Enhanced Thin cluster support
|
8
|
+
|
9
|
+
Minor enhancements:
|
10
|
+
* Used convenient method #application_action to define action method for phased restart
|
11
|
+
* Updated gem dependency on luban to version 0.6.7
|
12
|
+
* Renamed nginx template file for Thin/Puma for better file naming conventions
|
13
|
+
* Added #public_files_path to specify static contents served by Rack application
|
14
|
+
* Added convenient methods to manage web servers:
|
15
|
+
* #web_servers_available to get web servers available to use
|
16
|
+
* #current_web_server to get web server being currently used
|
17
|
+
* #web_servers_unused to get web server NOT being currently used
|
18
|
+
* Overloaded template filter method #exclude_template? to properly avoid rendering profile for web servers that are not currently used
|
19
|
+
* Added convenient methods, #tcp_socket? and #unix_socket?, to properly determine whether tcp or unix socket is being specified
|
20
|
+
* Rename #set_default_web_server_options to #set_web_server_options for better clarity
|
21
|
+
* Minor code cleanup
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
Bug fixes:
|
26
|
+
* Refactored #default_templates_path to fix an inheritance issue
|
27
|
+
* Corrected the process matching regular expressions
|
28
|
+
|
3
29
|
## Version 0.1.2 (Jul 14, 2016)
|
4
30
|
|
5
31
|
New features:
|
@@ -31,10 +31,10 @@ module Luban
|
|
31
31
|
include Parameters
|
32
32
|
|
33
33
|
def default_templates_path
|
34
|
-
@default_templates_path ||=
|
34
|
+
@default_templates_path ||= base_templates_path(__FILE__).join(web_server[:name].to_s)
|
35
35
|
end
|
36
36
|
|
37
|
-
|
37
|
+
application_action "phased_restart_process", dispatch_to: :controller
|
38
38
|
|
39
39
|
protected
|
40
40
|
|
@@ -7,11 +7,15 @@ module Luban
|
|
7
7
|
include Parameters
|
8
8
|
include WebServer
|
9
9
|
|
10
|
+
def exclude_template?(template)
|
11
|
+
web_servers_unused.any? { |w| template =~ /^#{w}\./ }
|
12
|
+
end
|
13
|
+
|
10
14
|
protected
|
11
15
|
|
12
16
|
def init
|
13
17
|
super
|
14
|
-
|
18
|
+
set_web_server_options unless task.opts.release.nil?
|
15
19
|
end
|
16
20
|
|
17
21
|
def web_server_module(path)
|
@@ -3,7 +3,6 @@ module Luban
|
|
3
3
|
module Applications
|
4
4
|
class Rack
|
5
5
|
class Controller < Luban::Deployment::Application::Controller
|
6
|
-
include Luban::Deployment::Service::Controller::Cluster
|
7
6
|
include Paths
|
8
7
|
include Parameters
|
9
8
|
include WebServer
|
@@ -35,7 +34,7 @@ module Luban
|
|
35
34
|
|
36
35
|
def init
|
37
36
|
super
|
38
|
-
|
37
|
+
set_web_server_options
|
39
38
|
end
|
40
39
|
|
41
40
|
def restart_process!
|
@@ -4,31 +4,15 @@ module Luban
|
|
4
4
|
class Rack
|
5
5
|
module Paths
|
6
6
|
def log_file_name
|
7
|
-
@log_file_name ||= "#{
|
7
|
+
@log_file_name ||= "#{current_web_server}.log"
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
11
|
-
|
12
|
-
@pid_file_path ||= pids_path.join(pid_file_name)
|
13
|
-
else
|
14
|
-
pids_path.join(pid_file_name(n))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def pid_file_name(n = nil)
|
19
|
-
if n.nil?
|
20
|
-
@pid_file_name ||= "#{web_server[:name]}.pid"
|
21
|
-
else
|
22
|
-
"#{web_server[:name]}.#{n + web_server[:opts][:port].to_i}.pid"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def pid_file_pattern
|
27
|
-
@pid_file_pattern ||= "#{web_server[:name]}.*.pid"
|
10
|
+
def pid_file_name
|
11
|
+
@pid_file_name ||= "#{current_web_server}.pid"
|
28
12
|
end
|
29
13
|
|
30
14
|
def control_file_name
|
31
|
-
@control_file_name ||= "#{
|
15
|
+
@control_file_name ||= "#{current_web_server}.#{control_file_extname}"
|
32
16
|
end
|
33
17
|
|
34
18
|
def control_file_extname
|
@@ -36,28 +20,23 @@ module Luban
|
|
36
20
|
end
|
37
21
|
|
38
22
|
def logrotate_file_name
|
39
|
-
@logrotate_file_name ||= "#{
|
23
|
+
@logrotate_file_name ||= "#{current_web_server}.logrotate"
|
24
|
+
end
|
25
|
+
|
26
|
+
def socket_file_path
|
27
|
+
@socket_file_path ||= sockets_path.join(socket_file_name)
|
40
28
|
end
|
41
29
|
|
42
30
|
def sockets_path
|
43
31
|
@sockets_path ||= shared_path.join('sockets')
|
44
32
|
end
|
45
33
|
|
46
|
-
def
|
47
|
-
|
48
|
-
@socket_file_path ||= sockets_path.join(socket_file_name)
|
49
|
-
else
|
50
|
-
sockets_path.join(socket_file_name(n))
|
51
|
-
end
|
34
|
+
def socket_file_name
|
35
|
+
@socket_file_name ||= "#{current_web_server}.sock"
|
52
36
|
end
|
53
37
|
|
54
|
-
def
|
55
|
-
|
56
|
-
@socket_file_name ||= "#{web_server[:name]}.sock"
|
57
|
-
else
|
58
|
-
"#{web_server[:name]}.#{n}.sock"
|
59
|
-
end
|
60
|
-
|
38
|
+
def public_files_path
|
39
|
+
@public_files_path ||= release_path.join('public')
|
61
40
|
end
|
62
41
|
|
63
42
|
def ruby_bin_path
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Logrotate configuration for Puma
|
2
|
+
|
3
|
+
<%= log_path.join('puma*.log') %> {
|
4
|
+
daily
|
5
|
+
missingok
|
6
|
+
rotate 14
|
7
|
+
compress
|
8
|
+
dateext
|
9
|
+
notifempty
|
10
|
+
sharedscripts
|
11
|
+
postrotate
|
12
|
+
[ ! -f <%= pid_file_path %> ] || kill -HUP $(cat <%= pid_file_path %>) 2>/dev/null || true
|
13
|
+
endscript
|
14
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Monit configuration for Puma
|
2
|
+
|
3
|
+
<% opts = web_server[:opts] -%>
|
4
|
+
check process <%= service_entry %>
|
5
|
+
with pidfile <%= pid_file_path %>
|
6
|
+
onreboot laststate
|
7
|
+
start program = "/bin/bash -c 'sleep 1; <%= start_command %>'"
|
8
|
+
stop program = "/bin/bash -c '<%= stop_command %>'"
|
9
|
+
if totalmem is greater than 150.0 MB for 40 cycles then alert
|
10
|
+
<%- if tcp_socket? -%>
|
11
|
+
if failed port <%= opts[:port] %> for 4 times within 8 cycles then restart
|
12
|
+
<%- end -%>
|
13
|
+
<%- if unix_socket? -%>
|
14
|
+
if failed unixsocket <%= socket_file_path %> for 4 times within 8 cycles then restart
|
15
|
+
<%- end -%>
|
16
|
+
if cpu is greater than 80% for 20 cycles then alert
|
17
|
+
if loadavg(5min) greater than 10 for 40 cycles then alert
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# Nginx reverse proxy configuration for Puma
|
2
|
+
|
3
|
+
<% opts = web_server[:opts] -%>
|
4
|
+
upstream <%= service_entry %> {
|
5
|
+
# fail_timeout=0 means we always retry an upstream even if it failed
|
6
|
+
# to return a good HTTP response
|
7
|
+
|
8
|
+
<%- if tcp_socket? -%>
|
9
|
+
server <%= opts[:address] %>:<%= opts[:port] %> fail_timeout=0;
|
10
|
+
<%- end -%>
|
11
|
+
<%- if unix_socket? -%>
|
12
|
+
server unix:<%= socket_file_path %> fail_timeout=0;
|
13
|
+
<%- end -%>
|
14
|
+
}
|
15
|
+
|
16
|
+
server {
|
17
|
+
listen <%= port %>;
|
18
|
+
server_name <%= virtual_host %>;
|
19
|
+
|
20
|
+
# ~2 seconds is often enough for most cases to parse HTML/CSS and
|
21
|
+
# retrieve needed images/icons/frames, connections are cheap in
|
22
|
+
# nginx so increasing this is generally safe...
|
23
|
+
keepalive_timeout 5;
|
24
|
+
|
25
|
+
# path for static files
|
26
|
+
root <%= public_files_path %>;
|
27
|
+
|
28
|
+
location ~ ^/assets/ {
|
29
|
+
gzip_static on; # to serve pre-gizpped version
|
30
|
+
expires 1y;
|
31
|
+
add_header Cache-Control public;
|
32
|
+
add_header ETag "";
|
33
|
+
break;
|
34
|
+
}
|
35
|
+
|
36
|
+
try_files $uri/index.html $uri.html $uri @app;
|
37
|
+
|
38
|
+
location @app {
|
39
|
+
proxy_pass http://<%= service_entry %>;
|
40
|
+
}
|
41
|
+
}
|
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
<% opts = web_server[:opts] -%>
|
4
4
|
<% opts[:servers].times do |n| -%>
|
5
|
-
check process <%= service_entry %>.<%=
|
5
|
+
check process <%= service_entry %>.<%= current_web_server %>.<%= n %>
|
6
6
|
with pidfile <%= pid_file_path(n) %>
|
7
7
|
group <%= service_entry %>
|
8
8
|
onreboot laststate
|
9
9
|
start program = "/bin/bash -c 'sleep 1; <%= start_command %> -o <%=n %>'"
|
10
10
|
stop program = "/bin/bash -c '<%= stop_command %> -o <%=n %>'"
|
11
11
|
if totalmem is greater than 150.0 MB for 40 cycles then alert
|
12
|
-
<%- if
|
12
|
+
<%- if tcp_socket? -%>
|
13
13
|
if failed port <%= opts[:port] + n %> for 4 times within 8 cycles then restart
|
14
14
|
<%- end -%>
|
15
|
-
<%- if
|
15
|
+
<%- if unix_socket? -%>
|
16
16
|
if failed unixsocket <%= socket_file_path(n) %> for 4 times within 8 cycles then restart
|
17
17
|
<%- end -%>
|
18
18
|
if cpu is greater than 80% for 20 cycles then alert
|
@@ -5,12 +5,12 @@ upstream <%= service_entry %> {
|
|
5
5
|
# fail_timeout=0 means we always retry an upstream even if it failed
|
6
6
|
# to return a good HTTP response
|
7
7
|
|
8
|
-
<%- if
|
8
|
+
<%- if tcp_socket? -%>
|
9
9
|
<%- opts[:servers].times do |n| -%>
|
10
10
|
server <%= opts[:address] %>:<%= opts[:port] + n %> fail_timeout=0;
|
11
11
|
<%- end -%>
|
12
12
|
<%- end -%>
|
13
|
-
<%- if
|
13
|
+
<%- if unix_socket? -%>
|
14
14
|
<%- opts[:servers].times do |n| -%>
|
15
15
|
server unix:<%= socket_file_path(n) %> fail_timeout=0;
|
16
16
|
<%- end -%>
|
@@ -27,7 +27,7 @@ server {
|
|
27
27
|
keepalive_timeout 5;
|
28
28
|
|
29
29
|
# path for static files
|
30
|
-
root <%=
|
30
|
+
root <%= public_files_path %>;
|
31
31
|
|
32
32
|
location ~ ^/assets/ {
|
33
33
|
gzip_static on; # to serve pre-gizpped version
|
@@ -9,6 +9,16 @@ module Luban
|
|
9
9
|
raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
|
10
10
|
end
|
11
11
|
|
12
|
+
def web_servers_available
|
13
|
+
@web_servers ||= [:thin, :puma]
|
14
|
+
end
|
15
|
+
|
16
|
+
def web_servers_unused
|
17
|
+
@web_servers_unused ||= web_servers_available.select { |s| s != current_web_server }
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_web_server; web_server[:name]; end
|
21
|
+
|
12
22
|
protected
|
13
23
|
|
14
24
|
def init
|
@@ -19,11 +29,11 @@ module Luban
|
|
19
29
|
require web_server_require_path
|
20
30
|
singleton_class.send(:prepend, web_server_module(web_server_require_path))
|
21
31
|
rescue LoadError => e
|
22
|
-
abort "Aborted! Failed to load web server #{
|
32
|
+
abort "Aborted! Failed to load web server #{current_web_server.inspect}."
|
23
33
|
end
|
24
34
|
|
25
35
|
def web_server_require_path
|
26
|
-
@web_server_require_path ||= web_server_require_root.join(
|
36
|
+
@web_server_require_path ||= web_server_require_root.join(current_web_server.to_s)
|
27
37
|
end
|
28
38
|
|
29
39
|
def web_server_require_root
|
@@ -34,7 +44,7 @@ module Luban
|
|
34
44
|
@web_server_module ||= Object.const_get(path.to_s.camelcase, false)
|
35
45
|
end
|
36
46
|
|
37
|
-
def
|
47
|
+
def set_web_server_options
|
38
48
|
web_server[:opts] = default_web_server_options.merge(web_server[:opts])
|
39
49
|
end
|
40
50
|
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module Luban
|
2
|
+
module Deployment
|
3
|
+
module Applications
|
4
|
+
class Rack
|
5
|
+
module WebServers
|
6
|
+
module Puma
|
7
|
+
module Common
|
8
|
+
def default_web_server_options
|
9
|
+
@default_web_server_options ||= {
|
10
|
+
# Server options
|
11
|
+
address: "0.0.0.0",
|
12
|
+
port: port,
|
13
|
+
socket: socket_file_path.to_s,
|
14
|
+
directory: release_path.to_s,
|
15
|
+
environment: stage,
|
16
|
+
# Daemon options
|
17
|
+
daemonize: true,
|
18
|
+
pidfile: pid_file_path.to_s,
|
19
|
+
state_path: state_file_path.to_s,
|
20
|
+
redirect_stdout: log_file_path.to_s,
|
21
|
+
redirect_stderr: error_log_file_path.to_s,
|
22
|
+
redirect_append: true,
|
23
|
+
quiet: false,
|
24
|
+
tag: "#{env_name}:#{release_tag}",
|
25
|
+
# Cluster options
|
26
|
+
servers: 2,
|
27
|
+
threads: "5:5",
|
28
|
+
preload: false,
|
29
|
+
prune_bundler: true,
|
30
|
+
# Control app options
|
31
|
+
control_socket: control_socket_file_path.to_s,
|
32
|
+
control_opts: { authen_tocken: port.to_s }
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def tcp_socket?; @tcp_socket; end
|
37
|
+
def unix_socket?; @unix_socket; end
|
38
|
+
|
39
|
+
def state_file_path
|
40
|
+
@state_file_path ||= pids_path.join(state_file_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def state_file_name
|
44
|
+
@state_file_name ||= "#{current_web_server}.state"
|
45
|
+
end
|
46
|
+
|
47
|
+
def error_log_file_path
|
48
|
+
@error_log_file_path ||= log_path.join("#{current_web_server}_error.log")
|
49
|
+
end
|
50
|
+
|
51
|
+
def control_socket_file_path
|
52
|
+
@control_socket_file_path ||= sockets_path.join(control_socket_file_name)
|
53
|
+
end
|
54
|
+
|
55
|
+
def control_socket_file_name
|
56
|
+
@control_socket_file_name ||= "#{current_web_server}ctl.sock"
|
57
|
+
end
|
58
|
+
|
59
|
+
def puma_command
|
60
|
+
@puma_command ||= "#{bundle_executable} exec pumactl -F #{control_file_path}"
|
61
|
+
end
|
62
|
+
|
63
|
+
def start_command
|
64
|
+
@start_command ||= "cd #{release_path}; #{puma_command} start"
|
65
|
+
end
|
66
|
+
|
67
|
+
def stop_command
|
68
|
+
@stop_command ||= "cd #{release_path}; #{puma_command} stop"
|
69
|
+
end
|
70
|
+
|
71
|
+
def process_pattern
|
72
|
+
@process_pattern ||= "^puma .+\\[#{Regexp.escape(env_name)}:.*\\]"
|
73
|
+
end
|
74
|
+
|
75
|
+
def service_entry
|
76
|
+
@serivce_entry ||= "#{super}.#{current_web_server}"
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
def set_web_server_options
|
82
|
+
super.tap do |opts|
|
83
|
+
[:uri, :stdout_redirect, :workers, :threads, :control, :tuning].each do |param|
|
84
|
+
send("set_#{param}_options", opts)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def set_uri_options(opts)
|
90
|
+
socket = opts.delete(:socket)
|
91
|
+
address = opts.delete(:address)
|
92
|
+
port = opts.delete(:port)
|
93
|
+
@unix_socket = !!opts.delete(:unix_socket)
|
94
|
+
@tcp_socket = !@unix_socket
|
95
|
+
if unix_socket?
|
96
|
+
opts[:bind] = "unix://#{socket}"
|
97
|
+
else
|
98
|
+
opts[:bind] = "tcp://#{address}:#{port}"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def set_stdout_redirect_options(opts)
|
103
|
+
redirect_stdout = opts.delete(:redirect_stdout)
|
104
|
+
redirect_stderr = opts.delete(:redirect_stderr)
|
105
|
+
redirect_append = opts.delete(:redirect_append)
|
106
|
+
opts[:stdout_redirect] = [ redirect_stdout, redirect_stderr, redirect_append ]
|
107
|
+
end
|
108
|
+
|
109
|
+
def set_workers_options(opts)
|
110
|
+
opts[:workers] = opts.delete(:servers)
|
111
|
+
end
|
112
|
+
|
113
|
+
def set_threads_options(opts)
|
114
|
+
if opts[:threads].is_a?(String)
|
115
|
+
opts[:threads] = opts[:threads].split(":").map(&:to_i)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def set_control_options(opts)
|
120
|
+
control_socket = opts.delete(:control_socket)
|
121
|
+
control_socket = "unix://#{control_socket}" unless control_socket == 'auto'
|
122
|
+
control_opts = opts.delete(:control_opts)
|
123
|
+
opts[:activate_control_app] = [ control_socket, control_opts ]
|
124
|
+
end
|
125
|
+
|
126
|
+
def set_tuning_options(opts)
|
127
|
+
if opts[:prune_bundler]
|
128
|
+
opts.delete(:preload)
|
129
|
+
elsif opts[:preload]
|
130
|
+
opts.delete(:prune_bundler)
|
131
|
+
opts[:preload_app!] = opts.delete(:preload)
|
132
|
+
else
|
133
|
+
opts.delete(:prune_bundler)
|
134
|
+
opts.delete(:preload)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def parameterize(*args)
|
139
|
+
args.map(&:inspect).join(", ")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
include Common
|
144
|
+
|
145
|
+
def restart_command
|
146
|
+
@restart_command ||= "cd #{release_path}; #{puma_command} restart"
|
147
|
+
end
|
148
|
+
|
149
|
+
def phased_restart_command
|
150
|
+
@phased_restart_command ||= "cd #{release_path}; #{puma_command} phased-restart"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -4,7 +4,87 @@ module Luban
|
|
4
4
|
class Rack
|
5
5
|
module WebServers
|
6
6
|
module Thin
|
7
|
+
module Cluster
|
8
|
+
def pid_file_pattern
|
9
|
+
@pid_file_pattern ||= "#{current_web_server}.*.pid"
|
10
|
+
end
|
11
|
+
|
12
|
+
def pid_files_path
|
13
|
+
pids_path.join(pid_file_pattern)
|
14
|
+
end
|
15
|
+
|
16
|
+
def pid_files
|
17
|
+
capture(:ls, "-A #{pid_files_path} 2>/dev/null").split.map do |f|
|
18
|
+
Pathname.new(f)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def pids
|
23
|
+
pid_files.collect { |pid_file| capture(:cat, "#{pid_file} 2>/dev/null") }
|
24
|
+
end
|
25
|
+
|
26
|
+
def pid; pids; end
|
27
|
+
|
28
|
+
def pid_file_exists?
|
29
|
+
# Any pid file is NOT zero size
|
30
|
+
pid_files.any? { |pid_file| file?(pid_file, "-s") }
|
31
|
+
end
|
32
|
+
|
33
|
+
def remove_orphaned_pid_file
|
34
|
+
rm(pid_files_path) if pid_file_orphaned?
|
35
|
+
end
|
36
|
+
|
37
|
+
def monitor_command
|
38
|
+
@monitor_command ||= "#{monitor_executable} monitor -g #{service_entry}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def unmonitor_command
|
42
|
+
@unmonitor_command ||= "#{monitor_executable} unmonitor -g #{service_entry}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
module Paths
|
47
|
+
def pid_file_path(n = nil)
|
48
|
+
if n.nil?
|
49
|
+
@pid_file_path ||= pids_path.join(pid_file_name)
|
50
|
+
else
|
51
|
+
pids_path.join(pid_file_name(n))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def pid_file_name(n = nil)
|
56
|
+
if n.nil?
|
57
|
+
@pid_file_name ||= "#{current_web_server}.pid"
|
58
|
+
else
|
59
|
+
"#{current_web_server}.#{n + web_server[:opts][:port].to_i}.pid"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def control_file_extname
|
64
|
+
@control_file_extname ||= "yml"
|
65
|
+
end
|
66
|
+
|
67
|
+
def socket_file_path(n = nil)
|
68
|
+
if n.nil?
|
69
|
+
@socket_file_path ||= sockets_path.join(socket_file_name)
|
70
|
+
else
|
71
|
+
sockets_path.join(socket_file_name(n))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def socket_file_name(n = nil)
|
76
|
+
if n.nil?
|
77
|
+
@socket_file_name ||= "#{current_web_server}.sock"
|
78
|
+
else
|
79
|
+
"#{current_web_server}.#{n}.sock"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
7
84
|
module Common
|
85
|
+
include Cluster
|
86
|
+
include Paths
|
87
|
+
|
8
88
|
def default_web_server_options
|
9
89
|
@default_web_server_options ||= {
|
10
90
|
# Server options
|
@@ -12,7 +92,6 @@ module Luban
|
|
12
92
|
port: port + 1,
|
13
93
|
socket: socket_file_path.to_s,
|
14
94
|
chdir: release_path.to_s,
|
15
|
-
# Adapter options
|
16
95
|
environment: stage,
|
17
96
|
# Daemon options
|
18
97
|
daemonize: true,
|
@@ -20,7 +99,7 @@ module Luban
|
|
20
99
|
pid: pid_file_path.to_s,
|
21
100
|
tag: "#{env_name}:#{release_tag}",
|
22
101
|
# Cluster options
|
23
|
-
servers:
|
102
|
+
servers: 2,
|
24
103
|
wait: 30,
|
25
104
|
# Tuning options
|
26
105
|
timeout: 30,
|
@@ -31,9 +110,8 @@ module Luban
|
|
31
110
|
}
|
32
111
|
end
|
33
112
|
|
34
|
-
def
|
35
|
-
|
36
|
-
end
|
113
|
+
def tcp_socket?; @tcp_socket; end
|
114
|
+
def unix_socket?; @unix_socket; end
|
37
115
|
|
38
116
|
def thin_command
|
39
117
|
@thin_command ||= "#{bundle_executable} exec thin -C #{control_file_path}"
|
@@ -48,14 +126,16 @@ module Luban
|
|
48
126
|
end
|
49
127
|
|
50
128
|
def process_pattern
|
51
|
-
@process_pattern ||= "^thin server.+\\[#{Regexp.escape(env_name)}
|
129
|
+
@process_pattern ||= "^thin server.+\\[#{Regexp.escape(env_name)}:.*\\]"
|
52
130
|
end
|
53
131
|
|
54
132
|
protected
|
55
133
|
|
56
|
-
def
|
134
|
+
def set_web_server_options
|
57
135
|
super.tap do |opts|
|
58
|
-
|
136
|
+
@unix_socket = !!opts.delete(:unix_socket)
|
137
|
+
@tcp_socket = !@unix_socket
|
138
|
+
if unix_socket?
|
59
139
|
opts.delete(:address)
|
60
140
|
opts.delete(:port)
|
61
141
|
else
|
@@ -64,7 +144,7 @@ module Luban
|
|
64
144
|
end
|
65
145
|
end
|
66
146
|
end
|
67
|
-
|
147
|
+
|
68
148
|
include Common
|
69
149
|
|
70
150
|
def restart_command
|
data/luban-rack.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
22
|
spec.required_ruby_version = ">= 2.1.0"
|
23
|
-
spec.add_dependency 'luban'
|
23
|
+
spec.add_dependency 'luban', ">= 0.6.7"
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.12"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luban-rack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rubyist Chi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: luban
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.6.7
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.6.7
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,12 +88,17 @@ files:
|
|
88
88
|
- lib/luban/deployment/applications/rack/configurator.rb
|
89
89
|
- lib/luban/deployment/applications/rack/controller.rb
|
90
90
|
- lib/luban/deployment/applications/rack/paths.rb
|
91
|
-
- lib/luban/deployment/applications/rack/templates/
|
91
|
+
- lib/luban/deployment/applications/rack/templates/puma/puma.logrotate.erb
|
92
|
+
- lib/luban/deployment/applications/rack/templates/puma/puma.monitrc.erb
|
93
|
+
- lib/luban/deployment/applications/rack/templates/puma/puma.nginx.http.proxy.conf.erb
|
94
|
+
- lib/luban/deployment/applications/rack/templates/puma/puma.rb.erb
|
92
95
|
- lib/luban/deployment/applications/rack/templates/thin/thin.logrotate.erb
|
93
96
|
- lib/luban/deployment/applications/rack/templates/thin/thin.monitrc.erb
|
97
|
+
- lib/luban/deployment/applications/rack/templates/thin/thin.nginx.http.proxy.conf.erb
|
94
98
|
- lib/luban/deployment/applications/rack/templates/thin/thin.yml.erb
|
95
99
|
- lib/luban/deployment/applications/rack/version.rb
|
96
100
|
- lib/luban/deployment/applications/rack/web_server.rb
|
101
|
+
- lib/luban/deployment/applications/rack/web_servers/puma.rb
|
97
102
|
- lib/luban/deployment/applications/rack/web_servers/thin.rb
|
98
103
|
- lib/luban/rack.rb
|
99
104
|
- luban-rack.gemspec
|