capistrano-runit-puma 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41d1ad3edcb0ea6b5f08c8c0b86a000010358141
4
- data.tar.gz: 5cd2de426525c85aeac0da6bad8b54c59ae14782
3
+ metadata.gz: a59229ab3e25b6c7ffaa1d6e5e822a845b70aef1
4
+ data.tar.gz: 47293eaac0eca5bd6d54f6b4b5d3967538670c36
5
5
  SHA512:
6
- metadata.gz: 468cec02588887fba78d19a0a048f5238b97a8fa54c2340883a8397ef9bc4bf454cf17a0a7acd9fd1c57b8b8ba2482723acc5c1b8df0c6f5b0bd350c6d13260d
7
- data.tar.gz: 5e71bcb197935816cacdede308805e38da7fd63e93ad92212e143a38c3a69fa68b3ab6dad2161c89b438bf8eded7f539b0bee8edcb0187b1926a51aca0cb9f2c
6
+ metadata.gz: 955cade143980d9bc9c19e8de9e0bc17a02d9b94ac1f553f5aef2d111d51df4d5ead397d9bbfeb33358c27b9a44010f7924e7ddc0c68370da88e04799b609495
7
+ data.tar.gz: 331e0c7c266ffb4f2a0d94c14cf9953660760fd7253c7587dc6219dec006eec1bd2295179bae0ed6741f94cab34d88feb2ea004f6621f35d5d93df88145a18a0
data/README.md CHANGED
@@ -39,19 +39,19 @@ require 'capistrano/runit/puma'
39
39
  * `runit_puma_role` -- what host roles uses runit to run puma. Default value: `:app`
40
40
  * `runit_puma_default_hooks` -- run default hooks for runit puma or not. Default value: `true`.
41
41
  * `runit_puma_run_template` -- path to ERB template of `run` file. Default value: `nil`.
42
- * `runit_puma_workers` -- number of puma workers. Default value: 1.
42
+ * `runit_puma_workers` -- number of puma workers. Default value: 0.
43
43
  * `runit_puma_threads_min` -- minimal threads to use. Default value: 0.
44
44
  * `runit_puma_threads_max` -- maximal threads to use. Default value: 16.
45
- * `runit_puma_bind` -- bind URI. Examples: tcp://127.0.0.1:8080, unix:///tmp/puma.sock. Default value: nil.
45
+ * `runit_puma_bind` -- bind URI. Examples: tcp://127.0.0.1:8080, unix:///tmp/puma.sock. It can be set per server. Default value: nil.
46
46
  * `runit_puma_rackup` -- Path to application's rackup file. Default value: `File.join(current_path, 'config.ru')`
47
47
  * `runit_puma_state` -- Path to puma's state file. Default value: `File.join(shared_path, 'tmp', 'pids', 'puma.state')`
48
48
  * `runit_puma_pid` -- Path to pid file. Default value: `File.join(shared_path, 'tmp', 'pids', 'puma.pid')`
49
- * `runit_puma_bind` -- Puma's bind string. Default value: `File.join('unix://', shared_path, 'tmp', 'sockets', 'puma.sock')`
50
49
  * `runit_puma_conf` -- Path to puma's config file. Default value: `File.join(shared_path, 'puma.rb')`
51
- * `runit_puma_access_log` -- Path to puma's access log. Default value: `File.join(shared_path, 'log', 'puma_access.log')`
52
- * `runit_puma_error_log` -- Path to puma's error log. Default value: `File.join(shared_path, 'log', 'puma_access.log')`
50
+ * `runit_puma_log` -- path to puma's log (stdout/stderr combined). Default value: `File.join(shared_path, 'log', 'puma.log')`
53
51
  * `runit_puma_init_active_record` -- Enable or not establish ActiveRecord connection. Default value: `false`
54
- * `runit_puma_preload_app` -- Preload application. Default value: `true`
52
+ * `runit_puma_preload_app` -- Preload application. Default value: `false`
53
+ * `runit_puma_restart_method` -- One of following methods: `:restart` (default), `:force_restart`, `:phased_restart`.
54
+ * `runit_puma_on_worker_boot` -- Custom `on_worker_boot`code as string. Default value: nil.
55
55
 
56
56
  ## Contributing
57
57
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "capistrano-runit-puma"
5
- spec.version = '0.1.0'
5
+ spec.version = '0.2.0'
6
6
  spec.author = ['Oleksandr Simonov', 'Anton Ageev']
7
7
  spec.email = ['alex@simonov.me', 'antage@gmail.com']
8
8
  spec.summary = %q{Capistrano3 tasks for manage puma via runit supervisor.}
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.files = `git ls-files -z`.split("\x0")
14
14
  spec.require_paths = ["lib"]
15
15
 
16
- spec.add_runtime_dependency 'capistrano-runit-core', '~> 0.1.0'
16
+ spec.add_runtime_dependency 'capistrano-runit-core', '~> 0.2.0'
17
17
  spec.add_development_dependency "bundler", "~> 1.6"
18
18
  spec.add_development_dependency "rake"
19
19
  end
@@ -5,8 +5,7 @@ namespace :load do
5
5
  task :defaults do
6
6
  set :runit_puma_role, -> { :app }
7
7
  set :runit_puma_default_hooks, -> { true }
8
- set :runit_puma_run_template, nil
9
- set :runit_puma_workers, 1
8
+ set :runit_puma_workers, 0
10
9
  set :runit_puma_threads_min, 0
11
10
  set :runit_puma_threads_max, 16
12
11
  set :runit_puma_rackup, -> { File.join(current_path, 'config.ru') }
@@ -15,13 +14,14 @@ namespace :load do
15
14
  set :runit_puma_bind, -> { File.join('unix://', shared_path, 'tmp', 'sockets', 'puma.sock') }
16
15
  set :runit_puma_conf, -> { File.join(shared_path, 'puma.rb') }
17
16
  set :runit_puma_conf_in_repo, -> { false }
18
- set :runit_puma_access_log, -> { File.join(shared_path, 'log', 'puma_access.log') }
19
- set :runit_puma_error_log, -> { File.join(shared_path, 'log', 'puma_error.log') }
17
+ set :runit_puma_log, -> { File.join(shared_path, 'log', 'puma.log') }
20
18
  set :runit_puma_init_active_record, false
21
- set :runit_puma_preload_app, true
19
+ set :runit_puma_preload_app, false
20
+ set :runit_puma_restart_method, :restart
21
+ set :runit_puma_on_worker_boot, nil
22
22
  # Rbenv and RVM integration
23
- set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(puma pumactl))
24
- set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(puma pumactl))
23
+ set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w(puma))
24
+ set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w(puma))
25
25
  end
26
26
  end
27
27
 
@@ -55,8 +55,13 @@ namespace :runit do
55
55
  array.compact.join(' ')
56
56
  end
57
57
 
58
- def create_puma_default_conf
59
- warn 'puma.rb NOT FOUND!'
58
+ def create_puma_default_conf(host)
59
+ info 'Create or overwrite puma.rb'
60
+ # requirements
61
+ if host.fetch(:runit_puma_bind).nil? && fetch(:runit_puma_bind).nil?
62
+ $stderr.puts "You should set 'runit_puma_bind' variable globally or for host #{host.hostname}."
63
+ exit 1
64
+ end
60
65
  path = File.expand_path('../../templates/puma.rb.erb', __FILE__)
61
66
  if File.file?(path)
62
67
  template = ERB.new(File.read(path))
@@ -68,16 +73,26 @@ namespace :runit do
68
73
 
69
74
  task :add_default_hooks do
70
75
  after 'deploy:check', 'runit:puma:check'
71
- after 'deploy:finished', 'runit:puma:restart'
76
+ case fetch(:runit_puma_restart_method)
77
+ when :restart
78
+ after 'deploy:published', 'runit:puma:restart'
79
+ when :force_restart
80
+ after 'deploy:published', 'runit:puma:force_restart'
81
+ when :phased_restart
82
+ after 'deploy:published', 'runit:puma:phased_restart'
83
+ else
84
+ $stderr.puts 'Unknown restart method in runit_puma_restart_method variable. Allowed methods: :restart, :force_restart, :phased_restart.'
85
+ exit 1
86
+ end
72
87
  end
73
88
 
74
89
  task :check do
75
90
  check_service('puma')
76
- on roles fetch(:runit_puma_role) do
91
+ on roles fetch(:runit_puma_role) do |host|
77
92
  if test "[ -d #{puma_enabled_service_dir} ]"
78
93
  # Create puma.rb for new deployments if not in repo
79
- if !fetch(:runit_puma_conf_in_repo) && !test("[ -f #{fetch(:runit_puma_conf)} ]")
80
- create_puma_default_conf
94
+ if !fetch(:runit_puma_conf_in_repo)
95
+ create_puma_default_conf(host)
81
96
  end
82
97
  else
83
98
  error "Puma runit service isn't enabled."
@@ -87,12 +102,7 @@ namespace :runit do
87
102
 
88
103
  desc 'Setup puma runit service'
89
104
  task :setup do
90
- # requirements
91
- if fetch(:runit_puma_bind).nil?
92
- $stderr.puts "You should set 'runit_puma_bind' variable."
93
- exit 1
94
- end
95
- setup_service('puma', collect_sidekiq_run_command)
105
+ setup_service('puma', collect_puma_run_command)
96
106
  end
97
107
 
98
108
  desc 'Enable puma runit service'
@@ -120,16 +130,14 @@ namespace :runit do
120
130
  on roles fetch(:runit_puma_role) do
121
131
  if test "[ -d #{puma_enabled_service_dir} ]"
122
132
  if test("[ -f #{fetch(:runit_puma_pid)} ]") && test("kill -0 $( cat #{fetch(:runit_puma_pid)} )")
123
- within current_path do
124
- execute :bundle, :exec, :pumactl, "-S #{fetch(:runit_puma_state)} restart"
125
- end
133
+ runit_execute_command('puma', '2')
126
134
  else
127
135
  info 'Puma is not running'
128
136
  if test("[ -f #{fetch(:runit_puma_pid)} ]")
129
137
  info 'Removing broken pid file'
130
138
  execute :rm, '-f', fetch(:runit_puma_pid)
131
139
  end
132
- execute "#{fetch(:runit_sv_path)} start #{puma_enabled_service_dir}"
140
+ runit_execute_command('puma', 'start')
133
141
  end
134
142
  else
135
143
  error "Puma runit service isn't enabled."
@@ -4,11 +4,11 @@ daemonize false
4
4
  quiet
5
5
  pidfile '<%= fetch(:runit_puma_pid)%>'
6
6
  state_path '<%= fetch(:runit_puma_state)%>'
7
- stdout_redirect '<%= fetch(:runit_puma_access_log)%>', '<%= fetch(:runit_puma_error_log)%>', true
7
+ stdout_redirect '<%= fetch(:runit_puma_log)%>', '<%= fetch(:runit_puma_log)%>', true
8
8
 
9
9
  workers <%= fetch(:runit_puma_workers, 1) %>
10
10
  threads <%= fetch(:runit_puma_threads_min, 0) %>, <%= fetch(:runit_puma_threads_max, 16) %>
11
- bind "<%= fetch(:runit_puma_bind) %>"
11
+ bind "<%= host.fetch(:runit_puma_bind) or fetch(:runit_puma_bind) %>"
12
12
 
13
13
  <% if fetch(:runit_puma_preload_app) %>
14
14
  preload_app!
@@ -19,10 +19,15 @@ on_restart do
19
19
  ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{current_path}/Gemfile") %>"
20
20
  end
21
21
 
22
+ <% if fetch(:runit_puma_init_active_record) %>
22
23
  on_worker_boot do
23
- <% if fetch(:runit_puma_init_active_record) %>
24
- ActiveSupport.on_load(:active_record) do
25
- ActiveRecord::Base.establish_connection
24
+ ::ActiveSupport.on_load(:active_record) do
25
+ ::ActiveRecord::Base.establish_connection
26
26
  end
27
- <% end %>
28
27
  end
28
+ <% end %>
29
+ <% unless fetch(:runit_puma_on_worker_boot, nil).nil? %>
30
+ on_worker_boot do
31
+ <%= fetch(:runit_puma_on_worker_boot) %>
32
+ end
33
+ <% end %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-runit-puma
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksandr Simonov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-09-29 00:00:00.000000000 Z
12
+ date: 2015-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano-runit-core
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 0.1.0
20
+ version: 0.2.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 0.1.0
27
+ version: 0.2.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: bundler
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -91,8 +91,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.2.2
94
+ rubygems_version: 2.4.6
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Capistrano3 tasks for manage puma via runit supervisor.
98
98
  test_files: []
99
+ has_rdoc: