capistrano3-puma 2.0.0 → 3.0.0

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: 28c9c75dc6f8d76315e7c45f93ae6bd942057082
4
- data.tar.gz: 7853f2ad6ded69548d582ab4e1d7ec8b8d537955
3
+ metadata.gz: d4dc9950a23bafe870cddd6646561016a410f1d4
4
+ data.tar.gz: 42ce480b729df2bc98880303cc709cd137963f78
5
5
  SHA512:
6
- metadata.gz: 3cf44c290adb44ccaa6a600426e25afb8a24e063cc3dd64c6f1fc154fea4c7aca19b700221e7d885fcc32305b3bf5f78419d15730639d98d9e7fe17e8a54d3ec
7
- data.tar.gz: 17b823002d40963e1d67a6e968f59d96ab108627bda03d7af9275bcf31773de254620ca0daf86fe70eaf0da37712b30628d1ff9a0e022becc1068b409beac292
6
+ metadata.gz: daa0d11b90a4c1a9707d5c6d9b3435592bb383a8ea35cb8d4f4ca9a82b775c241533b0570a48599fe5d1fc39b053a1f6474b22ff494fc0f0abad78ee333eb193
7
+ data.tar.gz: 4f8f739a71eab448a9a778d2f9fdceeecf28f4b4cdd96efebfaaef64f95f266aa7c3a00ddd20da9988a89098d7afcff104749382d1b48768b1a07e862a0a8b10
data/CHANGELOG.md CHANGED
@@ -1,4 +1,10 @@
1
1
  ## Changelog
2
+ - 3.0.0:
3
+ - Require capistrano 3.7+
4
+ - Implement the plugin system
5
+ - don't fail if puma was already running
6
+ - Added :puma_daemonize option (default is false)
7
+
2
8
  - 2.0.0:
3
9
  - Require puma 3.4+
4
10
  - Require Capistrano 3.5+
data/CONTRIBUTORS.md CHANGED
@@ -3,12 +3,14 @@
3
3
  Abdelkader Boudih
4
4
  André Arko
5
5
  Ariel Zerahia
6
- ayaya
6
+ Barack Obama
7
+ Bart de Water
8
+ Benjamin Kim
7
9
  Bin Huang
8
10
  Bryan Liles
9
11
  Claudio Poli
10
12
  Cyril Rohr
11
- dfang
13
+ Eric
12
14
  Fritz Lee
13
15
  Hnat Kubov
14
16
  Ivan Schneider
@@ -25,21 +27,28 @@ Konstantin Papkovskiy
25
27
  Kyle Decot
26
28
  Lisa Hagemann
27
29
  Lonre Wang
28
- marshall-lee
30
+ Lucas Alves
31
+ Marcos Chicote
29
32
  Matias De Santi
30
33
  Michael C. Beck
31
34
  Molfar
32
- msbrigna
33
35
  Neil Bartley
34
36
  Peter
37
+ Philippe Nénert
35
38
  Ponomarev Nikolay
36
39
  Rafael Goulart
37
40
  RavWar
38
- ruohan.chen
39
41
  Ruslan
42
+ SHIMADA Koji
40
43
  Sergey Ponomarev
41
44
  Shane O'Grady
42
45
  Simon Males
43
46
  Steve Madere
44
47
  Suhail Patel
45
48
  Suraj Shirvankar
49
+ ayaya
50
+ dfang
51
+ marshall-lee
52
+ mizukmb
53
+ msbrigna
54
+ ruohan.chen
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2013-2016 Abdelkader Boudih
3
+ Copyright (c) 2013-2017 Abdelkader Boudih
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -20,10 +20,10 @@ And then execute:
20
20
  # Capfile
21
21
 
22
22
  require 'capistrano/puma'
23
- require 'capistrano/puma/workers' # if you want to control the workers (in cluster mode)
24
- require 'capistrano/puma/jungle' # if you need the jungle tasks
25
- require 'capistrano/puma/monit' # if you need the monit tasks
26
- require 'capistrano/puma/nginx' # if you want to upload a nginx site template
23
+ install_plugin Capistrano::Puma::Workers # if you want to control the workers (in cluster mode)
24
+ install_plugin Capistrano::Puma::Jungle # if you need the jungle tasks
25
+ install_plugin Capistrano::Puma::Monit # if you need the monit tasks
26
+ install_plugin Capistrano::Puma::Nginx # if you want to upload a nginx site template
27
27
  ```
28
28
 
29
29
  ### Config
@@ -113,6 +113,7 @@ Configurable options, shown here with defaults: Please note the configuration op
113
113
  set :puma_worker_timeout, nil
114
114
  set :puma_init_active_record, false
115
115
  set :puma_preload_app, false
116
+ set :puma_daemonize, true
116
117
  set :puma_plugins, [] #accept array of plugins
117
118
  set :nginx_use_ssl, false
118
119
  ```
@@ -5,7 +5,7 @@ require 'capistrano/puma/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'capistrano3-puma'
8
- spec.version = Capistrano::Puma::VERSION
8
+ spec.version = Capistrano::PumaVERSION
9
9
  spec.authors = ['Abdelkader Boudih']
10
10
  spec.email = ['Terminale@gmail.com']
11
11
  spec.description = %q{Puma integration for Capistrano 3}
@@ -18,7 +18,11 @@ Gem::Specification.new do |spec|
18
18
  spec.files = `git ls-files`.split($/)
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'capistrano', '~> 3.5'
21
+ spec.add_dependency 'capistrano', '~> 3.7'
22
22
  spec.add_dependency 'capistrano-bundler'
23
23
  spec.add_dependency 'puma' , '~> 3.4'
24
+ spec.post_install_message = %q{
25
+ [capistrano-puma] Plugins need to be explicitly installed with install_plugin.
26
+ Please see README.md
27
+ }
24
28
  end
@@ -1,2 +1,118 @@
1
1
  require 'capistrano/bundler'
2
- load File.expand_path('../tasks/puma.rake', __FILE__)
2
+ require "capistrano/plugin"
3
+
4
+ module Capistrano
5
+ module PumaCommon
6
+ def puma_switch_user(role, &block)
7
+ user = puma_user(role)
8
+ if user == role.user
9
+ block.call
10
+ else
11
+ as user do
12
+ block.call
13
+ end
14
+ end
15
+ end
16
+
17
+ def puma_user(role)
18
+ properties = role.properties
19
+ properties.fetch(:puma_user) || # local property for puma only
20
+ fetch(:puma_user) ||
21
+ properties.fetch(:run_as) || # global property across multiple capistrano gems
22
+ role.user
23
+ end
24
+
25
+ def puma_bind
26
+ Array(fetch(:puma_bind)).collect do |bind|
27
+ "bind '#{bind}'"
28
+ end.join("\n")
29
+ end
30
+
31
+
32
+ def template_puma(from, to, role)
33
+ file = [
34
+ "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
35
+ "lib/capistrano/templates/#{from}-#{role.hostname}.rb",
36
+ "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb",
37
+ "lib/capistrano/templates/#{from}.rb.erb",
38
+ "lib/capistrano/templates/#{from}.rb",
39
+ "lib/capistrano/templates/#{from}.erb",
40
+ "config/deploy/templates/#{from}.rb.erb",
41
+ "config/deploy/templates/#{from}.rb",
42
+ "config/deploy/templates/#{from}.erb",
43
+ File.expand_path("../templates/#{from}.erb", __FILE__),
44
+ ].detect { |path| File.file?(path) }
45
+ erb = File.read(file)
46
+ backend.upload! StringIO.new(ERB.new(erb, nil, '-').result(binding)), to
47
+ end
48
+ end
49
+
50
+ class Puma < Capistrano::Plugin
51
+ include PumaCommon
52
+
53
+ def define_tasks
54
+ eval_rakefile File.expand_path('../tasks/puma.rake', __FILE__)
55
+ end
56
+
57
+ def set_defaults
58
+ set_if_empty :puma_role, :app
59
+ set_if_empty :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
60
+ # Configure "min" to be the minimum number of threads to use to answer
61
+ # requests and "max" the maximum.
62
+ set_if_empty :puma_threads, [0, 16]
63
+ set_if_empty :puma_workers, 0
64
+ set_if_empty :puma_rackup, -> { File.join(current_path, 'config.ru') }
65
+ set_if_empty :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
66
+ set_if_empty :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
67
+ set_if_empty :puma_bind, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'puma.sock') }
68
+ set_if_empty :puma_default_control_app, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'pumactl.sock') }
69
+ set_if_empty :puma_conf, -> { File.join(shared_path, 'puma.rb') }
70
+ set_if_empty :puma_access_log, -> { File.join(shared_path, 'log', 'puma_access.log') }
71
+ set_if_empty :puma_error_log, -> { File.join(shared_path, 'log', 'puma_error.log') }
72
+ set_if_empty :puma_init_active_record, false
73
+ set_if_empty :puma_preload_app, false
74
+ set_if_empty :puma_daemonize, false
75
+
76
+ # Chruby, Rbenv and RVM integration
77
+ append :chruby_map_bins, 'puma', 'pumactl'
78
+ append :rbenv_map_bins, 'puma', 'pumactl'
79
+ append :rvm_map_bins, 'puma', 'pumactl'
80
+
81
+ # Bundler integration
82
+ append :bundle_bins, 'puma', 'pumactl'
83
+ end
84
+
85
+ def register_hooks
86
+ after 'deploy:check', 'puma:check'
87
+ after 'deploy:finished', 'puma:smart_restart'
88
+ end
89
+
90
+ def puma_workers
91
+ fetch(:puma_workers, 0)
92
+ end
93
+
94
+ def puma_preload_app?
95
+ fetch(:puma_preload_app)
96
+ end
97
+
98
+ def puma_daemonize?
99
+ fetch(:puma_daemonize)
100
+ end
101
+
102
+ def puma_plugins
103
+ Array(fetch(:puma_plugins)).collect do |bind|
104
+ "plugin '#{bind}'"
105
+ end.join("\n")
106
+ end
107
+
108
+ def upload_puma_rb(role)
109
+ template_puma 'puma.rb', fetch(:puma_conf), role
110
+ end
111
+ end
112
+ end
113
+ install_plugin Capistrano::Puma
114
+
115
+ require 'capistrano/puma/workers'
116
+ require 'capistrano/puma/monit'
117
+ require 'capistrano/puma/jungle'
118
+ require 'capistrano/puma/nginx'
@@ -1,2 +1,30 @@
1
- # Load jungle tasks
2
- load File.expand_path('../../tasks/jungle.rake', __FILE__)
1
+ module Capistrano
2
+ class Puma::Jungle < Capistrano::Plugin
3
+ include PumaCommon
4
+
5
+ def set_defaults
6
+ set_if_empty :puma_jungle_conf, '/etc/puma.conf'
7
+ set_if_empty :puma_run_path, '/usr/local/bin/run-puma'
8
+ end
9
+
10
+ def define_tasks
11
+ eval_rakefile File.expand_path('../../tasks/jungle.rake', __FILE__)
12
+ end
13
+
14
+ private
15
+
16
+ def debian_install
17
+ template_puma 'puma-deb', "#{fetch(:tmp_dir)}/puma", @role
18
+ execute "chmod +x #{fetch(:tmp_dir)}/puma"
19
+ sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
20
+ sudo 'update-rc.d -f puma defaults'
21
+ end
22
+
23
+ def rhel_install
24
+ template_puma 'puma-rpm', "#{fetch(:tmp_dir)}/puma", @role
25
+ execute "chmod +x #{fetch(:tmp_dir)}/puma"
26
+ sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
27
+ sudo 'chkconfig --add puma'
28
+ end
29
+ end
30
+ end
@@ -1,2 +1,30 @@
1
- # Load monit tasks
2
- load File.expand_path('../../tasks/monit.rake', __FILE__)
1
+ module Capistrano
2
+ class Puma::Monit < Capistrano::Plugin
3
+ def register_hooks
4
+ before 'deploy:updating', 'puma:monit:unmonitor'
5
+ after 'deploy:published', 'puma:monit:monitor'
6
+ end
7
+
8
+ def define_tasks
9
+ eval_rakefile File.expand_path('../../tasks/monit.rake', __FILE__)
10
+ end
11
+
12
+ def set_defaults
13
+ set_if_empty :puma_monit_conf_dir, -> { "/etc/monit/conf.d/#{puma_monit_service_name}.conf" }
14
+ set_if_empty :puma_monit_use_sudo, true
15
+ set_if_empty :puma_monit_bin, '/usr/bin/monit'
16
+ end
17
+
18
+ def puma_monit_service_name
19
+ fetch(:puma_monit_service_name, "puma_#{fetch(:application)}_#{fetch(:stage)}")
20
+ end
21
+
22
+ def sudo_if_needed(command)
23
+ if fetch(:puma_monit_use_sudo)
24
+ sudo command
25
+ else
26
+ execute command
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1 +1,20 @@
1
- load File.expand_path('../../tasks/nginx.rake', __FILE__)
1
+ module Capistrano
2
+ class Puma::Nginx < Capistrano::Plugin
3
+ include PumaCommon
4
+ def set_defaults
5
+ # Nginx and puma configuration
6
+ set_if_empty :nginx_config_name, "#{fetch(:application)}_#{fetch(:stage)}"
7
+ set_if_empty :nginx_sites_available_path, '/etc/nginx/sites-available'
8
+ set_if_empty :nginx_sites_enabled_path, '/etc/nginx/sites-enabled'
9
+ set_if_empty :nginx_server_name, "localhost #{fetch(:application)}.local"
10
+ set_if_empty :nginx_flags, 'fail_timeout=0'
11
+ set_if_empty :nginx_http_flags, fetch(:nginx_flags)
12
+ set_if_empty :nginx_socket_flags, fetch(:nginx_flags)
13
+ set_if_empty :nginx_use_ssl, false
14
+ end
15
+
16
+ def define_tasks
17
+ eval_rakefile File.expand_path('../../tasks/nginx.rake', __FILE__)
18
+ end
19
+ end
20
+ end
@@ -1,5 +1,3 @@
1
1
  module Capistrano
2
- module Puma
3
- VERSION = '2.0.0'
4
- end
2
+ PumaVERSION = '3.0.0'
5
3
  end
@@ -1,2 +1,7 @@
1
- # Load monit tasks
2
- load File.expand_path('../../tasks/workers.rake', __FILE__)
1
+ module Capistrano
2
+ class Puma::Workers < Capistrano::Plugin
3
+ def define_tasks
4
+ eval_rakefile File.expand_path('../../tasks/workers.rake', __FILE__)
5
+ end
6
+ end
7
+ end
@@ -1,27 +1,20 @@
1
- namespace :load do
2
- task :defaults do
3
- set :puma_jungle_conf, '/etc/puma.conf'
4
- set :puma_run_path, '/usr/local/bin/run-puma'
5
- end
6
- end
7
-
1
+ git_plugin = self
8
2
 
9
3
  namespace :puma do
10
4
  namespace :jungle do
11
-
12
5
  desc 'Install Puma jungle'
13
6
  task :install do
14
7
  on roles(fetch(:puma_role)) do |role|
15
8
  @role = role
16
- template_puma 'run-puma', "#{fetch(:tmp_dir)}/run-puma", role
9
+ git_plugin.template_puma 'run-puma', "#{fetch(:tmp_dir)}/run-puma", role
17
10
  execute "chmod +x #{fetch(:tmp_dir)}/run-puma"
18
11
  sudo "mv #{fetch(:tmp_dir)}/run-puma #{fetch(:puma_run_path)}"
19
12
  if test '[ -f /etc/redhat-release ]'
20
13
  #RHEL flavor OS
21
- rhel_install
14
+ git_plugin.rhel_install
22
15
  elsif test '[ -f /etc/lsb-release ]'
23
16
  #Debian flavor OS
24
- debian_install
17
+ git_plugin.debian_install
25
18
  else
26
19
  #Some other OS
27
20
  error 'This task is not supported for your OS'
@@ -30,23 +23,6 @@ namespace :puma do
30
23
  end
31
24
  end
32
25
 
33
-
34
- def debian_install
35
- template_puma 'puma-deb', "#{fetch(:tmp_dir)}/puma", @role
36
- execute "chmod +x #{fetch(:tmp_dir)}/puma"
37
- sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
38
- sudo 'update-rc.d -f puma defaults'
39
-
40
- end
41
-
42
- def rhel_install
43
- template_puma 'puma-rpm', "#{fetch(:tmp_dir)}/puma" , @role
44
- execute "chmod +x #{fetch(:tmp_dir)}/puma"
45
- sudo "mv #{fetch(:tmp_dir)}/puma /etc/init.d/puma"
46
- sudo 'chkconfig --add puma'
47
- end
48
-
49
-
50
26
  desc 'Setup Puma config and install jungle script'
51
27
  task :setup do
52
28
  invoke 'puma:config'
@@ -76,6 +52,5 @@ namespace :puma do
76
52
  end
77
53
  end
78
54
  end
79
-
80
55
  end
81
56
  end
@@ -1,10 +1,4 @@
1
- namespace :load do
2
- task :defaults do
3
- set :puma_monit_conf_dir, -> { "/etc/monit/conf.d/#{puma_monit_service_name}.conf" }
4
- set :puma_monit_use_sudo, true
5
- set :puma_monit_bin, '/usr/bin/monit'
6
- end
7
- end
1
+ git_plugin = self
8
2
 
9
3
  namespace :puma do
10
4
  namespace :monit do
@@ -12,7 +6,7 @@ namespace :puma do
12
6
  task :config do
13
7
  on roles(fetch(:puma_role)) do |role|
14
8
  @role = role
15
- template_puma 'puma_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", @role
9
+ git_plugin.template_puma 'puma_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", @role
16
10
  sudo_if_needed "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:puma_monit_conf_dir)}"
17
11
  sudo_if_needed "#{fetch(:puma_monit_bin)} reload"
18
12
  end
@@ -62,20 +56,5 @@ namespace :puma do
62
56
  end
63
57
  end
64
58
 
65
- before 'deploy:updating', 'puma:monit:unmonitor'
66
- after 'deploy:published', 'puma:monit:monitor'
67
-
68
- def puma_monit_service_name
69
- fetch(:puma_monit_service_name, "puma_#{fetch(:application)}_#{fetch(:stage)}")
70
- end
71
-
72
- def sudo_if_needed(command)
73
- if fetch(:puma_monit_use_sudo)
74
- sudo command
75
- else
76
- execute command
77
- end
78
- end
79
-
80
59
  end
81
60
  end
@@ -1,22 +1,11 @@
1
- namespace :load do
2
- task :defaults do
3
- # Nginx and puma configuration
4
- set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
5
- set :nginx_sites_available_path, -> { '/etc/nginx/sites-available' }
6
- set :nginx_sites_enabled_path, -> { '/etc/nginx/sites-enabled' }
7
- set :nginx_server_name, -> { "localhost #{fetch(:application)}.local" }
8
- set :nginx_flags, -> { 'fail_timeout=0' }
9
- set :nginx_http_flags, -> { fetch(:nginx_flags) }
10
- set :nginx_socket_flags, -> { fetch(:nginx_flags) }
11
- set :nginx_use_ssl, false
12
- end
13
- end
1
+ git_plugin = self
2
+
14
3
  namespace :puma do
15
4
  desc 'Setup nginx configuration'
16
5
  task :nginx_config do
17
6
  on roles(fetch(:puma_nginx, :web)) do |role|
18
- puma_switch_user(role) do
19
- template_puma('nginx_conf', "/tmp/nginx_#{fetch(:nginx_config_name)}", role)
7
+ git_plugin.puma_switch_user(role) do
8
+ git_plugin.template_puma('nginx_conf', "/tmp/nginx_#{fetch(:nginx_config_name)}", role)
20
9
  sudo :mv, "/tmp/nginx_#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)}"
21
10
  sudo :ln, '-fs', "#{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_enabled_path)}/#{fetch(:nginx_config_name)}"
22
11
  end
@@ -1,52 +1,17 @@
1
- namespace :load do
2
- task :defaults do
3
- set :puma_default_hooks, -> { true }
4
- set :puma_role, :app
5
- set :puma_env, -> { fetch(:rack_env, fetch(:rails_env, fetch(:stage))) }
6
- # Configure "min" to be the minimum number of threads to use to answer
7
- # requests and "max" the maximum.
8
- set :puma_threads, [0, 16]
9
- set :puma_workers, 0
10
- set :puma_rackup, -> { File.join(current_path, 'config.ru') }
11
- set :puma_state, -> { File.join(shared_path, 'tmp', 'pids', 'puma.state') }
12
- set :puma_pid, -> { File.join(shared_path, 'tmp', 'pids', 'puma.pid') }
13
- set :puma_bind, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'puma.sock') }
14
- set :puma_default_control_app, -> { File.join("unix://#{shared_path}", 'tmp', 'sockets', 'pumactl.sock') }
15
- set :puma_conf, -> { File.join(shared_path, 'puma.rb') }
16
- set :puma_access_log, -> { File.join(shared_path, 'log', 'puma_access.log') }
17
- set :puma_error_log, -> { File.join(shared_path, 'log', 'puma_error.log') }
18
- set :puma_init_active_record, false
19
- set :puma_preload_app, false
20
-
21
- # Chruby, Rbenv and RVM integration
22
- append :chruby_map_bins, 'puma', 'pumactl'
23
- append :rbenv_map_bins, 'puma', 'pumactl'
24
- append :rvm_map_bins, 'puma', 'pumactl'
25
-
26
- # Bundler integration
27
- append :bundle_bins, 'puma', 'pumactl'
28
- end
29
- end
30
-
31
- namespace :deploy do
32
- before :starting, :check_puma_hooks do
33
- invoke 'puma:add_default_hooks' if fetch(:puma_default_hooks)
34
- end
35
- end
1
+ git_plugin = self
36
2
 
37
3
  namespace :puma do
38
-
39
4
  desc 'Setup Puma config file'
40
5
  task :config do
41
6
  on roles(fetch(:puma_role)) do |role|
42
- template_puma 'puma', fetch(:puma_conf), role
7
+ git_plugin.upload_puma_rb(role)
43
8
  end
44
9
  end
45
10
 
46
11
  desc 'Start puma'
47
12
  task :start do
48
- on roles (fetch(:puma_role)) do |role|
49
- puma_switch_user(role) do
13
+ on roles(fetch(:puma_role)) do |role|
14
+ git_plugin.puma_switch_user(role) do
50
15
  if test "[ -f #{fetch(:puma_conf)} ]"
51
16
  info "using conf file #{fetch(:puma_conf)}"
52
17
  else
@@ -71,7 +36,7 @@ namespace :puma do
71
36
  task command do
72
37
  on roles (fetch(:puma_role)) do |role|
73
38
  within current_path do
74
- puma_switch_user(role) do
39
+ git_plugin.puma_switch_user(role) do
75
40
  with rack_env: fetch(:puma_env) do
76
41
  if test "[ -f #{fetch(:puma_pid)} ]"
77
42
  if test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
@@ -96,7 +61,7 @@ namespace :puma do
96
61
  task command do
97
62
  on roles (fetch(:puma_role)) do |role|
98
63
  within current_path do
99
- puma_switch_user(role) do
64
+ git_plugin.puma_switch_user(role) do
100
65
  with rack_env: fetch(:puma_env) do
101
66
  if test "[ -f #{fetch(:puma_pid)} ]" and test :kill, "-0 $( cat #{fetch(:puma_pid)} )"
102
67
  # NOTE pid exist but state file is nonsense, so ignore that case
@@ -113,12 +78,11 @@ namespace :puma do
113
78
  end
114
79
 
115
80
  task :check do
116
- on roles (fetch(:puma_role)) do |role|
81
+ on roles(fetch(:puma_role)) do |role|
117
82
  #Create puma.rb for new deployments
118
83
  unless test "[ -f #{fetch(:puma_conf)} ]"
119
84
  warn 'puma.rb NOT FOUND!'
120
- #TODO DRY
121
- template_puma 'puma', fetch(:puma_conf), role
85
+ git_plugin.upload_puma_rb(role)
122
86
  info 'puma.rb generated'
123
87
  end
124
88
  end
@@ -126,77 +90,11 @@ namespace :puma do
126
90
 
127
91
 
128
92
  task :smart_restart do
129
- if !puma_preload_app? && puma_workers.to_i > 1
93
+ if !git_plugin.puma_preload_app? && git_plugin.puma_workers.to_i > 1
130
94
  invoke 'puma:phased-restart'
131
95
  else
132
96
  invoke 'puma:restart'
133
97
  end
134
98
  end
135
99
 
136
- def puma_switch_user(role, &block)
137
- user = puma_user(role)
138
- if user == role.user
139
- block.call
140
- else
141
- as user do
142
- block.call
143
- end
144
- end
145
- end
146
-
147
- def puma_user(role)
148
- properties = role.properties
149
- properties.fetch(:puma_user) || # local property for puma only
150
- fetch(:puma_user) ||
151
- properties.fetch(:run_as) || # global property across multiple capistrano gems
152
- role.user
153
- end
154
-
155
- def puma_workers
156
- fetch(:puma_workers, 0)
157
- end
158
-
159
- def puma_preload_app?
160
- fetch(:puma_preload_app)
161
- end
162
-
163
- def puma_bind
164
- Array(fetch(:puma_bind)).collect do |bind|
165
- "bind '#{bind}'"
166
- end.join("\n")
167
- end
168
-
169
- def puma_plugins
170
- Array(fetch(:puma_plugins)).collect do |bind|
171
- "plugin '#{bind}'"
172
- end.join("\n")
173
- end
174
-
175
- def template_puma(from, to, role)
176
- [
177
- "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
178
- "lib/capistrano/templates/#{from}-#{role.hostname}.rb",
179
- "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb",
180
- "lib/capistrano/templates/#{from}.rb.erb",
181
- "lib/capistrano/templates/#{from}.rb",
182
- "lib/capistrano/templates/#{from}.erb",
183
- "config/deploy/templates/#{from}.rb.erb",
184
- "config/deploy/templates/#{from}.rb",
185
- "config/deploy/templates/#{from}.erb",
186
- File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
187
- File.expand_path("../../templates/#{from}.erb", __FILE__)
188
- ].each do |path|
189
- if File.file?(path)
190
- erb = File.read(path)
191
- upload! StringIO.new(ERB.new(erb, nil, '-').result(binding)), to
192
- break
193
- end
194
- end
195
- end
196
-
197
- task :add_default_hooks do
198
- after 'deploy:check', 'puma:check'
199
- after 'deploy:finished', 'puma:smart_restart'
200
- end
201
-
202
100
  end
@@ -1,14 +1,16 @@
1
+ git_plugin = self
2
+
1
3
  namespace :puma do
2
4
  namespace :workers do
3
5
  desc 'Add a worker'
4
6
  task :count do
5
- on roles (fetch(:puma_role)) do |role|
6
- puma_switch_user(role) do
7
- #TODO
8
- # cleanup
9
- # add host name/ip
10
- workers_count = capture("ps ax | grep -c 'puma: cluster worker [0-9]: `cat #{fetch(:puma_pid)}`'").to_i - 1
11
- log "Workers count : #{workers_count}"
7
+ on roles(fetch(:puma_role)) do |role|
8
+ git_plugin.puma_switch_user(role) do
9
+ #TODO
10
+ # cleanup
11
+ # add host name/ip
12
+ workers_count = capture("ps ax | grep -c 'puma: cluster worker [0-9]: `cat #{fetch(:puma_pid)}`'").to_i - 1
13
+ log "Workers count : #{workers_count}"
12
14
  end
13
15
  end
14
16
  end
@@ -19,8 +21,8 @@ namespace :puma do
19
21
  # Refactor
20
22
  desc 'Worker++'
21
23
  task :more do
22
- on roles (fetch(:puma_role)) do |role|
23
- puma_switch_user(role) do
24
+ on roles(fetch(:puma_role)) do |role|
25
+ git_plugin.puma_switch_user(role) do
24
26
  execute(:kill, "-TTIN `cat #{fetch(:puma_pid)}`")
25
27
  end
26
28
  end
@@ -28,8 +30,8 @@ namespace :puma do
28
30
 
29
31
  desc 'Worker--'
30
32
  task :less do
31
- on roles (fetch(:puma_role)) do |role|
32
- puma_switch_user(role) do
33
+ on roles(fetch(:puma_role)) do |role|
34
+ git_plugin.puma_switch_user(role) do
33
35
  execute(:kill, "-TTOU `cat #{fetch(:puma_pid)}`")
34
36
  end
35
37
  end
@@ -24,6 +24,10 @@ workers <%= puma_workers %>
24
24
  worker_timeout <%= fetch(:puma_worker_timeout).to_i %>
25
25
  <% end %>
26
26
 
27
+ <% if puma_daemonize? %>
28
+ daemonize
29
+ <% end %>
30
+
27
31
  <% if puma_preload_app? %>
28
32
  preload_app!
29
33
  <% else %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano3-puma
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.5'
19
+ version: '3.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: '3.5'
26
+ version: '3.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: capistrano-bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -91,7 +91,8 @@ homepage: https://github.com/seuros/capistrano-puma
91
91
  licenses:
92
92
  - MIT
93
93
  metadata: {}
94
- post_install_message:
94
+ post_install_message: "\n [capistrano-puma] Plugins need to be explicitly installed
95
+ with install_plugin.\n Please see README.md\n "
95
96
  rdoc_options: []
96
97
  require_paths:
97
98
  - lib