luban-rack 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 88aed31e8c5bd4a6902db96f703cb1033697aa34
4
- data.tar.gz: a7c17e9b1bb17d88e222490bda22c95ed88441c2
3
+ metadata.gz: 75dff673fdfb8b910f2c8a5fc1c9a831cd5c313f
4
+ data.tar.gz: 6e16e73badf9284fa25dbc3957382089f99ff2c3
5
5
  SHA512:
6
- metadata.gz: 28b52f98ba0219a1bae69d782147c701f3a764be622b7cf9dfa1bb11ce459dfdaa48bcb38575495a990bb3fd5eb831d911ac7f5579e3980ec26d241331766ff6
7
- data.tar.gz: ebcccb620f86e27be90ae52f9ae015a26690925f81abe9911ecf408d4db7d111aeda73a205db971fb7c38cb910c62d06e6d11a7751dd65f84384e96f540b4d71
6
+ metadata.gz: 29bd4d9a3c43e62e1b9c1887eddffe4328039788f8c00e9197c241d455b64690cda4cee8bf2b2650a48d62d320bf715242d4f46026c4346998b7ef4e4fa813d6
7
+ data.tar.gz: c582a1f63b6871c4209e2b2836e792f1f16e905fa21730b194b4d0e7ec6f9c2f17114369ea33b9252bc0a24619579a5888508abd63979772f70fd99091c3f768
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ## Version 0.1.1 (Jul 11, 2016)
4
+
5
+ New features:
6
+ * Refactored web server for Rack to support cluster
7
+
3
8
  ## Version 0.1.0 (Jul 08, 2016)
4
9
 
5
10
  New features:
@@ -11,17 +11,21 @@ module Luban
11
11
 
12
12
  parameter :web_server
13
13
 
14
+ def power_by(server, **opts)
15
+ web_server name: server, opts: opts
16
+ end
17
+
14
18
  protected
15
19
 
16
20
  def set_default_rack_parameters
17
- set_default :web_server, DefaultWebServer
21
+ set_default :web_server, name: DefaultWebServer, opts: {}
18
22
  end
19
23
  end
20
24
 
21
25
  include Parameters
22
26
 
23
27
  def default_templates_path
24
- @default_templates_path ||= super(__FILE__).join(web_server.to_s)
28
+ @default_templates_path ||= super(__FILE__).join(web_server[:name].to_s)
25
29
  end
26
30
 
27
31
  dispatch_task :phased_restart_process, to: :controller
@@ -3,21 +3,14 @@ module Luban
3
3
  module Applications
4
4
  class Rack
5
5
  class Configurator < Luban::Deployment::Application::Configurator
6
- using Luban::CLI::CoreRefinements
7
-
8
6
  include Paths
9
7
  include Parameters
8
+ include WebServer
10
9
 
11
10
  protected
12
11
 
13
- def init
14
- load_web_server
15
- end
16
-
17
- def load_web_server
18
- require_relative "web_servers/#{web_server}"
19
- server_module = WebServers.const_get(web_server.camelcase).const_get('Common')
20
- singleton_class.send(:prepend, server_module)
12
+ def web_server_module(path)
13
+ @web_server_module ||= super.const_get('Common')
21
14
  end
22
15
  end
23
16
  end
@@ -3,23 +3,10 @@ module Luban
3
3
  module Applications
4
4
  class Rack
5
5
  class Controller < Luban::Deployment::Application::Controller
6
- using Luban::CLI::CoreRefinements
7
-
8
6
  include Luban::Deployment::Service::Controller::Cluster
9
7
  include Paths
10
8
  include Parameters
11
-
12
- def release_matched?
13
- release_tag =~ /^#{Regexp.escape(application_version)}/
14
- end
15
-
16
- def release_tag
17
- @release_tag ||= release_path.basename
18
- end
19
-
20
- def release_path
21
- @release_path ||= Pathname.new(readlink(app_path.join('app')))
22
- end
9
+ include WebServer
23
10
 
24
11
  def restart_process(phased: false)
25
12
  if process_stopped?
@@ -46,16 +33,6 @@ module Luban
46
33
 
47
34
  protected
48
35
 
49
- def init
50
- load_web_server
51
- end
52
-
53
- def load_web_server
54
- require_relative "web_servers/#{web_server}"
55
- server_module = WebServers.const_get(web_server.camelcase)
56
- singleton_class.send(:prepend, server_module)
57
- end
58
-
59
36
  def restart_process!
60
37
  capture("#{restart_command} 2>&1")
61
38
  end
@@ -4,19 +4,31 @@ module Luban
4
4
  class Rack
5
5
  module Paths
6
6
  def log_file_name
7
- @log_file_name ||= "#{web_server}.log"
7
+ @log_file_name ||= "#{web_server[:name]}.log"
8
8
  end
9
9
 
10
- def pid_file_name
11
- @pid_file_name ||= "#{web_server}.pid"
10
+ def pid_file_path(n = nil)
11
+ if n.nil?
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
12
24
  end
13
25
 
14
26
  def pid_file_pattern
15
- @pid_file_pattern ||= "#{web_server}.*.pid"
27
+ @pid_file_pattern ||= "#{web_server[:name]}.*.pid"
16
28
  end
17
29
 
18
30
  def control_file_name
19
- @control_file_name ||= "#{web_server}.#{control_file_extname}"
31
+ @control_file_name ||= "#{web_server[:name]}.#{control_file_extname}"
20
32
  end
21
33
 
22
34
  def control_file_extname
@@ -24,7 +36,7 @@ module Luban
24
36
  end
25
37
 
26
38
  def logrotate_file_name
27
- @logrotate_file_name ||= "#{web_server}.logrotate"
39
+ @logrotate_file_name ||= "#{web_server[:name]}.logrotate"
28
40
  end
29
41
 
30
42
  def sockets_path
@@ -36,7 +48,7 @@ module Luban
36
48
  end
37
49
 
38
50
  def socket_file_name
39
- @socket_file_name ||= "#{web_server}.sock"
51
+ @socket_file_name ||= "#{web_server[:name]}.sock"
40
52
  end
41
53
 
42
54
  def ruby_bin_path
@@ -1,6 +1,6 @@
1
1
  # Thin logrotate configuration
2
2
 
3
- <%= log_path.join('thin*.log') %> {
3
+ <%= log_path.join('thin.*.log') %> {
4
4
  daily
5
5
  missingok
6
6
  rotate 14
@@ -1,14 +1,21 @@
1
1
  # Monit Monit configuration for Thin
2
2
 
3
- check process <%= service_entry %>
4
- with pidfile <%= pid_file_path %>
5
- start program = "/bin/bash -c 'sleep 1; <%= start_command %>'"
6
- stop program = "/bin/bash -c '<%= stop_command %>'"
3
+ <% opts = web_server[:opts] -%>
4
+ <% opts[:servers].times do |n| -%>
5
+ check process <%= service_entry %>.<%= web_server[:name] %>.<%= n %>
6
+ with pidfile <%= pid_file_path(n) %>
7
+ group <%= service_entry %>
8
+ onreboot laststate
9
+ start program = "/bin/bash -c 'sleep 1; <%= start_command %> -o <%=n %>'"
10
+ stop program = "/bin/bash -c '<%= stop_command %> -o <%=n %>'"
7
11
  if totalmem is greater than 150.0 MB for 40 cycles then alert
8
- if failed port 3000 for 4 times within 8 cycles then restart
9
- if failed port 3001 for 4 times within 8 cycles then restart
10
- if failed port 3002 for 4 times within 8 cycles then restart
11
- if failed port 3003 for 4 times within 8 cycles then restart
12
- # if failed unixsocket <%= socket_file_path %> for 4 times within 8 cycles then restart
12
+ <%- if opts[:port] -%>
13
+ if failed port <%= opts[:port].to_i + n %> for 4 times within 8 cycles then restart
14
+ <%- end -%>
15
+ <%- if opts[:socket] -%>
16
+ if failed unixsocket <%= socket_file_path(n) %> for 4 times within 8 cycles then restart
17
+ <%- end -%>
13
18
  if cpu is greater than 80% for 20 cycles then alert
14
19
  if loadavg(5min) greater than 10 for 40 cycles then alert
20
+
21
+ <% end -%>
@@ -1,27 +1,4 @@
1
1
  ---
2
- # Server options
3
- # address: 0.0.0.0
4
- # port: 3000
5
- # socket: <%= socket_file_path %>
6
- chdir: <%= release_path %>
7
-
8
- # Adapter options
9
- environment: <%= stage %>
10
-
11
- # Daemon options
12
- daemonize: true
13
- log: <%= log_file_path %>
14
- pid: <%= pid_file_path %>
15
- tag: <%= "#{env_name}:#{release_tag}" %>
16
-
17
- # Cluster options
18
- servers: 4
19
- wait: 30
20
-
21
- # Tuning options
22
- # timeout: 30
23
- # max_conns: 1024
24
- # max_persistent_conns: 100
25
-
26
- # Common options
27
- # trace: true
2
+ <% web_server[:opts].each_pair do |key, value| -%>
3
+ <%= key %>: <%= value.inspect %>
4
+ <% end %>
@@ -2,7 +2,7 @@ module Luban
2
2
  module Deployment
3
3
  module Applications
4
4
  class Rack
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,45 @@
1
+ module Luban
2
+ module Deployment
3
+ module Applications
4
+ class Rack
5
+ module WebServer
6
+ using Luban::CLI::CoreRefinements
7
+
8
+ def default_web_server_options
9
+ raise NotImplementedError, "#{self.class.name}##{__method__} is an abstract method."
10
+ end
11
+
12
+ protected
13
+
14
+ def init
15
+ load_web_server
16
+ end
17
+
18
+ def load_web_server
19
+ require web_server_require_path
20
+ singleton_class.send(:prepend, web_server_module(web_server_require_path))
21
+ set_default_web_server_options
22
+ rescue LoadError => e
23
+ abort "Aborted! Failed to load web server #{web_server[:name].inspect}."
24
+ end
25
+
26
+ def web_server_require_path
27
+ @web_server_require_path ||= web_server_require_root.join(web_server[:name].to_s)
28
+ end
29
+
30
+ def web_server_require_root
31
+ @web_server_require_root ||= Pathname.new("luban/deployment/applications/rack/web_servers")
32
+ end
33
+
34
+ def web_server_module(path)
35
+ @web_server_module ||= Object.const_get(path.to_s.camelcase, false)
36
+ end
37
+
38
+ def set_default_web_server_options
39
+ web_server[:opts] = default_web_server_options.merge(web_server[:opts])
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -5,6 +5,32 @@ module Luban
5
5
  module WebServers
6
6
  module Thin
7
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: 3000,
13
+ socket: socket_file_path.to_s,
14
+ chdir: release_path.to_s,
15
+ # Adapter options
16
+ environment: stage,
17
+ # Daemon options
18
+ daemonize: true,
19
+ log: log_file_path.to_s,
20
+ pid: pid_file_path.to_s,
21
+ tag: "#{env_name}:#{release_tag}",
22
+ # Cluster options
23
+ servers: 4,
24
+ wait: 30,
25
+ # Tuning options
26
+ timeout: 30,
27
+ max_conns: 1024,
28
+ max_persistent_conns: 100,
29
+ # Common options
30
+ trace: true
31
+ }
32
+ end
33
+
8
34
  def control_file_extname
9
35
  @control_file_extname ||= "yml"
10
36
  end
@@ -24,6 +50,19 @@ module Luban
24
50
  def process_pattern
25
51
  @process_pattern ||= "^thin server.+\\[#{Regexp.escape(env_name)}:#{Regexp.escape(application_version)}-[0-9a-f]+\\]"
26
52
  end
53
+
54
+ protected
55
+
56
+ def set_default_web_server_options
57
+ super.tap do |opts|
58
+ if opts.delete(:unix_socket)
59
+ opts.delete(:address)
60
+ opts.delete(:port)
61
+ else
62
+ opts.delete(:socket)
63
+ end
64
+ end
65
+ end
27
66
  end
28
67
 
29
68
  include Common
@@ -1,6 +1,7 @@
1
1
  require 'luban'
2
2
  require_relative 'rack/base'
3
3
  require_relative 'rack/paths'
4
+ require_relative 'rack/web_server'
4
5
  require_relative 'rack/controller'
5
6
  require_relative 'rack/configurator'
6
7
  require_relative 'rack/version'
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.1.0
4
+ version: 0.1.1
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-07-08 00:00:00.000000000 Z
11
+ date: 2016-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: luban
@@ -92,6 +92,7 @@ files:
92
92
  - lib/luban/deployment/applications/rack/templates/thin/thin.monitrc.erb
93
93
  - lib/luban/deployment/applications/rack/templates/thin/thin.yml.erb
94
94
  - lib/luban/deployment/applications/rack/version.rb
95
+ - lib/luban/deployment/applications/rack/web_server.rb
95
96
  - lib/luban/deployment/applications/rack/web_servers/thin.rb
96
97
  - lib/luban/rack.rb
97
98
  - luban-rack.gemspec