capistrano3-puma 1.1.0 → 1.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 +4 -4
 - data/LICENSE.txt +1 -1
 - data/README.md +4 -0
 - data/lib/capistrano/puma.rb +1 -1
 - data/lib/capistrano/puma/jungle.rb +1 -1
 - data/lib/capistrano/puma/monit.rb +1 -1
 - data/lib/capistrano/puma/nginx.rb +1 -1
 - data/lib/capistrano/puma/version.rb +1 -1
 - data/lib/capistrano/puma/workers.rb +1 -1
 - data/lib/capistrano/tasks/{jungle.cap → jungle.rake} +0 -0
 - data/lib/capistrano/tasks/{monit.cap → monit.rake} +20 -9
 - data/lib/capistrano/tasks/nginx.rake +12 -0
 - data/lib/capistrano/tasks/{puma.cap → puma.rake} +49 -27
 - data/lib/capistrano/tasks/{workers.cap → workers.rake} +12 -8
 - data/lib/capistrano/templates/nginx_conf.erb +16 -0
 - data/lib/capistrano/templates/puma.rb.erb +1 -1
 - data/lib/capistrano/templates/puma_monit.conf.erb +2 -2
 - data/lib/capistrano/templates/run-puma.erb +2 -2
 - metadata +7 -7
 - data/lib/capistrano/tasks/nginx.cap +0 -10
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 1755f57fc22107e5f701181029fdfb83c371f812
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 9366f5b212d65fe58f2e9fca81ea523add36636b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: feccecc2474ff21ef7573ceed1fb04c050e24fb4c7be308842ca3cfc56fd9979bfd491f7c1334091dba292e34ba159692ca27d4901afec7bcc6c2a8b7f67ba8e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: d9d1bc5fdcefb10fc9d9b594febec02baca91d0de3093425e274a2e9e4211a1ec86789328afb6d90617787ff2701b7fe10b793cfb1299b5b46256f8257f2cd45
         
     | 
    
        data/LICENSE.txt
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -54,6 +54,7 @@ role :puma_nginx, %w{root@example.com} 
     | 
|
| 
       54 
54 
     | 
    
         
             
            Configurable options, shown here with defaults: Please note the configuration options below are not required unless you are trying to override a default setting, for instance if you are deploying on a host on which you do not have sudo or root privileges and you need to restrict the path. These settings go in the deploy.rb file.
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
            ```ruby
         
     | 
| 
      
 57 
     | 
    
         
            +
                set :puma_user, fetch(:user)
         
     | 
| 
       57 
58 
     | 
    
         
             
                set :puma_rackup, -> { File.join(current_path, 'config.ru') }
         
     | 
| 
       58 
59 
     | 
    
         
             
                set :puma_state, "#{shared_path}/tmp/pids/puma.state"
         
     | 
| 
       59 
60 
     | 
    
         
             
                set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
         
     | 
| 
         @@ -69,6 +70,7 @@ Configurable options, shown here with defaults: Please note the configuration op 
     | 
|
| 
       69 
70 
     | 
    
         
             
                set :puma_worker_timeout, nil
         
     | 
| 
       70 
71 
     | 
    
         
             
                set :puma_init_active_record, false
         
     | 
| 
       71 
72 
     | 
    
         
             
                set :puma_preload_app, true
         
     | 
| 
      
 73 
     | 
    
         
            +
                set :nginx_use_ssl, false
         
     | 
| 
       72 
74 
     | 
    
         
             
            ```
         
     | 
| 
       73 
75 
     | 
    
         
             
            For Jungle tasks (beta), these options exist:
         
     | 
| 
       74 
76 
     | 
    
         
             
            ```ruby
         
     | 
| 
         @@ -94,6 +96,7 @@ Ensure that the following directories are shared (via ``linked_dirs``): 
     | 
|
| 
       94 
96 
     | 
    
         
             
                tmp/pids tmp/sockets log
         
     | 
| 
       95 
97 
     | 
    
         | 
| 
       96 
98 
     | 
    
         
             
            ## Changelog
         
     | 
| 
      
 99 
     | 
    
         
            +
            - 1.2.0: add support for puma user for puma user @mcb & @seuros
         
     | 
| 
       97 
100 
     | 
    
         
             
            - 1.1.0: Set :puma_preload_app to false; Reload Monit after uploading any monit configuration; Always refresh Gemfile @rafaelgoulart @suhailpatel @sime
         
     | 
| 
       98 
101 
     | 
    
         
             
            - 1.0.0: Add activate control app @askagirl
         
     | 
| 
       99 
102 
     | 
    
         
             
            - 0.8.5: Fix smart_restart task to check if puma preloads app
         
     | 
| 
         @@ -138,6 +141,7 @@ Ensure that the following directories are shared (via ``linked_dirs``): 
     | 
|
| 
       138 
141 
     | 
    
         
             
            - [Jun Lin](https://github.com/linjunpop)
         
     | 
| 
       139 
142 
     | 
    
         
             
            - [fang duan](https://github.com/dfang)
         
     | 
| 
       140 
143 
     | 
    
         
             
            - [Steve Madere](https://github.com/stevemadere)
         
     | 
| 
      
 144 
     | 
    
         
            +
            - [Matias De Santi](https://github.com/mdesanti)
         
     | 
| 
       141 
145 
     | 
    
         | 
| 
       142 
146 
     | 
    
         
             
            ## Contributing
         
     | 
| 
       143 
147 
     | 
    
         | 
    
        data/lib/capistrano/puma.rb
    CHANGED
    
    | 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            load File.expand_path('../tasks/puma. 
     | 
| 
      
 1 
     | 
    
         
            +
            load File.expand_path('../tasks/puma.rake', __FILE__)
         
     | 
| 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Load jungle tasks
         
     | 
| 
       2 
     | 
    
         
            -
            load File.expand_path('../../tasks/jungle. 
     | 
| 
      
 2 
     | 
    
         
            +
            load File.expand_path('../../tasks/jungle.rake', __FILE__)
         
     | 
| 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Load monit tasks
         
     | 
| 
       2 
     | 
    
         
            -
            load File.expand_path('../../tasks/monit. 
     | 
| 
      
 2 
     | 
    
         
            +
            load File.expand_path('../../tasks/monit.rake', __FILE__)
         
     | 
| 
         @@ -1 +1 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            load File.expand_path('../../tasks/nginx. 
     | 
| 
      
 1 
     | 
    
         
            +
            load File.expand_path('../../tasks/nginx.rake', __FILE__)
         
     | 
| 
         @@ -1,2 +1,2 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # Load monit tasks
         
     | 
| 
       2 
     | 
    
         
            -
            load File.expand_path('../../tasks/workers. 
     | 
| 
      
 2 
     | 
    
         
            +
            load File.expand_path('../../tasks/workers.rake', __FILE__)
         
     | 
| 
         
            File without changes
         
     | 
| 
         @@ -1,11 +1,11 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            namespace :load do
         
     | 
| 
       2 
2 
     | 
    
         
             
              task :defaults do
         
     | 
| 
       3 
3 
     | 
    
         
             
                set :puma_monit_conf_dir, -> { "/etc/monit/conf.d/#{puma_monit_service_name}.conf" }
         
     | 
| 
       4 
     | 
    
         
            -
                set : 
     | 
| 
      
 4 
     | 
    
         
            +
                set :puma_monit_use_sudo, true
         
     | 
| 
      
 5 
     | 
    
         
            +
                set :puma_monit_bin, '/usr/bin/monit'
         
     | 
| 
       5 
6 
     | 
    
         
             
              end
         
     | 
| 
       6 
7 
     | 
    
         
             
            end
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
9 
     | 
    
         
             
            namespace :puma do
         
     | 
| 
       10 
10 
     | 
    
         
             
              namespace :monit do
         
     | 
| 
       11 
11 
     | 
    
         
             
                desc 'Config Puma monit-service'
         
     | 
| 
         @@ -13,49 +13,60 @@ namespace :puma do 
     | 
|
| 
       13 
13 
     | 
    
         
             
                  on roles(fetch(:puma_role)) do |role|
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @role = role
         
     | 
| 
       15 
15 
     | 
    
         
             
                    template_puma 'puma_monit.conf', "#{fetch(:tmp_dir)}/monit.conf", @role
         
     | 
| 
       16 
     | 
    
         
            -
                     
     | 
| 
       17 
     | 
    
         
            -
                     
     | 
| 
      
 16 
     | 
    
         
            +
                    sudo_if_needed "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:puma_monit_conf_dir)}"
         
     | 
| 
      
 17 
     | 
    
         
            +
                    sudo_if_needed "#{fetch(:puma_monit_bin)} reload"
         
     | 
| 
       18 
18 
     | 
    
         
             
                  end
         
     | 
| 
       19 
19 
     | 
    
         
             
                end
         
     | 
| 
       20 
20 
     | 
    
         | 
| 
       21 
21 
     | 
    
         
             
                desc 'Monitor Puma monit-service'
         
     | 
| 
       22 
22 
     | 
    
         
             
                task :monitor do
         
     | 
| 
       23 
23 
     | 
    
         
             
                  on roles(fetch(:puma_role)) do
         
     | 
| 
       24 
     | 
    
         
            -
                     
     | 
| 
      
 24 
     | 
    
         
            +
                    sudo_if_needed "#{fetch(:puma_monit_bin)} monitor #{puma_monit_service_name}"
         
     | 
| 
       25 
25 
     | 
    
         
             
                  end
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
                desc 'Unmonitor Puma monit-service'
         
     | 
| 
       29 
29 
     | 
    
         
             
                task :unmonitor do
         
     | 
| 
       30 
30 
     | 
    
         
             
                  on roles(fetch(:puma_role)) do
         
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
      
 31 
     | 
    
         
            +
                    sudo_if_needed "#{fetch(:puma_monit_bin)} unmonitor #{puma_monit_service_name}"
         
     | 
| 
       32 
32 
     | 
    
         
             
                  end
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
| 
       34 
34 
     | 
    
         | 
| 
       35 
35 
     | 
    
         
             
                desc 'Start Puma monit-service'
         
     | 
| 
       36 
36 
     | 
    
         
             
                task :start do
         
     | 
| 
       37 
37 
     | 
    
         
             
                  on roles(fetch(:puma_role)) do
         
     | 
| 
       38 
     | 
    
         
            -
                     
     | 
| 
      
 38 
     | 
    
         
            +
                    sudo_if_needed "#{fetch(:puma_monit_bin)} start #{puma_monit_service_name}"
         
     | 
| 
       39 
39 
     | 
    
         
             
                  end
         
     | 
| 
       40 
40 
     | 
    
         
             
                end
         
     | 
| 
       41 
41 
     | 
    
         | 
| 
       42 
42 
     | 
    
         
             
                desc 'Stop Puma monit-service'
         
     | 
| 
       43 
43 
     | 
    
         
             
                task :stop do
         
     | 
| 
       44 
44 
     | 
    
         
             
                  on roles(fetch(:puma_role)) do
         
     | 
| 
       45 
     | 
    
         
            -
                     
     | 
| 
      
 45 
     | 
    
         
            +
                    sudo_if_needed "#{fetch(:puma_monit_bin)}  stop #{puma_monit_service_name}"
         
     | 
| 
       46 
46 
     | 
    
         
             
                  end
         
     | 
| 
       47 
47 
     | 
    
         
             
                end
         
     | 
| 
       48 
48 
     | 
    
         | 
| 
       49 
49 
     | 
    
         
             
                desc 'Restart Puma monit-service'
         
     | 
| 
       50 
50 
     | 
    
         
             
                task :restart do
         
     | 
| 
       51 
51 
     | 
    
         
             
                  on roles(fetch(:puma_role)) do
         
     | 
| 
       52 
     | 
    
         
            -
                     
     | 
| 
      
 52 
     | 
    
         
            +
                    sudo_if_needed "#{fetch(:puma_monit_bin)} restart #{puma_monit_service_name}"
         
     | 
| 
       53 
53 
     | 
    
         
             
                  end
         
     | 
| 
       54 
54 
     | 
    
         
             
                end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
      
 56 
     | 
    
         
            +
                before 'deploy:updating', 'puma:monit:unmonitor'
         
     | 
| 
      
 57 
     | 
    
         
            +
                after 'deploy:published', 'puma:monit:monitor'
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
       56 
59 
     | 
    
         
             
                def puma_monit_service_name
         
     | 
| 
       57 
60 
     | 
    
         
             
                  fetch(:puma_monit_service_name, "puma_#{fetch(:application)}_#{fetch(:stage)}")
         
     | 
| 
       58 
61 
     | 
    
         
             
                end
         
     | 
| 
       59 
62 
     | 
    
         | 
| 
      
 63 
     | 
    
         
            +
                def sudo_if_needed(command)
         
     | 
| 
      
 64 
     | 
    
         
            +
                  if fetch(:puma_monit_use_sudo)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    sudo command
         
     | 
| 
      
 66 
     | 
    
         
            +
                  else
         
     | 
| 
      
 67 
     | 
    
         
            +
                    execute command
         
     | 
| 
      
 68 
     | 
    
         
            +
                  end
         
     | 
| 
      
 69 
     | 
    
         
            +
                end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
       60 
71 
     | 
    
         
             
              end
         
     | 
| 
       61 
72 
     | 
    
         
             
            end
         
     | 
| 
         @@ -0,0 +1,12 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            namespace :puma do
         
     | 
| 
      
 2 
     | 
    
         
            +
              desc 'Setup nginx configuration'
         
     | 
| 
      
 3 
     | 
    
         
            +
              task :nginx_config do
         
     | 
| 
      
 4 
     | 
    
         
            +
                on roles(fetch(:puma_nginx, :web)) do |role|
         
     | 
| 
      
 5 
     | 
    
         
            +
                  puma_switch_user(role) do
         
     | 
| 
      
 6 
     | 
    
         
            +
                    template_puma('nginx_conf', "/tmp/nginx_#{fetch(:nginx_config_name)}", role)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    sudo :mv, "/tmp/nginx_#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)}"
         
     | 
| 
      
 8 
     | 
    
         
            +
                    sudo :ln, '-fs', "#{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_enabled_path)}/#{fetch(:nginx_config_name)}"
         
     | 
| 
      
 9 
     | 
    
         
            +
                  end
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -31,6 +31,7 @@ namespace :load do 
     | 
|
| 
       31 
31 
     | 
    
         
             
                set :nginx_flags, -> { 'fail_timeout=0' }
         
     | 
| 
       32 
32 
     | 
    
         
             
                set :nginx_http_flags, -> { fetch(:nginx_flags) }
         
     | 
| 
       33 
33 
     | 
    
         
             
                set :nginx_socket_flags, -> { fetch(:nginx_flags) }
         
     | 
| 
      
 34 
     | 
    
         
            +
                set :nginx_use_ssl, false
         
     | 
| 
       34 
35 
     | 
    
         
             
              end
         
     | 
| 
       35 
36 
     | 
    
         
             
            end
         
     | 
| 
       36 
37 
     | 
    
         | 
| 
         @@ -51,16 +52,17 @@ namespace :puma do 
     | 
|
| 
       51 
52 
     | 
    
         | 
| 
       52 
53 
     | 
    
         
             
              desc 'Start puma'
         
     | 
| 
       53 
54 
     | 
    
         
             
              task :start do
         
     | 
| 
       54 
     | 
    
         
            -
                on roles (fetch(:puma_role)) do
         
     | 
| 
       55 
     | 
    
         
            -
                   
     | 
| 
       56 
     | 
    
         
            -
                     
     | 
| 
       57 
     | 
    
         
            -
             
     | 
| 
       58 
     | 
    
         
            -
                     
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
                     
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
      
 55 
     | 
    
         
            +
                on roles (fetch(:puma_role)) do |role|
         
     | 
| 
      
 56 
     | 
    
         
            +
                  puma_switch_user(role) do
         
     | 
| 
      
 57 
     | 
    
         
            +
                    if test "[ -f #{fetch(:puma_conf)} ]"
         
     | 
| 
      
 58 
     | 
    
         
            +
                      info "using conf file #{fetch(:puma_conf)}"
         
     | 
| 
      
 59 
     | 
    
         
            +
                    else
         
     | 
| 
      
 60 
     | 
    
         
            +
                      invoke 'puma:config'
         
     | 
| 
      
 61 
     | 
    
         
            +
                    end
         
     | 
| 
      
 62 
     | 
    
         
            +
                    within current_path do
         
     | 
| 
      
 63 
     | 
    
         
            +
                      with rack_env: fetch(:puma_env) do
         
     | 
| 
      
 64 
     | 
    
         
            +
                        execute :bundle, 'exec', :puma, "-C #{fetch(:puma_conf)} --daemon"
         
     | 
| 
      
 65 
     | 
    
         
            +
                      end
         
     | 
| 
       64 
66 
     | 
    
         
             
                    end
         
     | 
| 
       65 
67 
     | 
    
         
             
                  end
         
     | 
| 
       66 
68 
     | 
    
         
             
                end
         
     | 
| 
         @@ -71,17 +73,19 @@ namespace :puma do 
     | 
|
| 
       71 
73 
     | 
    
         
             
                task command do
         
     | 
| 
       72 
74 
     | 
    
         
             
                  on roles (fetch(:puma_role)) do
         
     | 
| 
       73 
75 
     | 
    
         
             
                    within current_path do
         
     | 
| 
       74 
     | 
    
         
            -
                       
     | 
| 
       75 
     | 
    
         
            -
                         
     | 
| 
       76 
     | 
    
         
            -
                          if test " 
     | 
| 
       77 
     | 
    
         
            -
                             
     | 
| 
      
 76 
     | 
    
         
            +
                      puma_switch_user(role) do
         
     | 
| 
      
 77 
     | 
    
         
            +
                        with rack_env: fetch(:puma_env) do
         
     | 
| 
      
 78 
     | 
    
         
            +
                          if test "[ -f #{fetch(:puma_pid)} ]"
         
     | 
| 
      
 79 
     | 
    
         
            +
                            if test "kill -0 $( cat #{fetch(:puma_pid)} )"
         
     | 
| 
      
 80 
     | 
    
         
            +
                              execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}"
         
     | 
| 
      
 81 
     | 
    
         
            +
                            else
         
     | 
| 
      
 82 
     | 
    
         
            +
                              # delete invalid pid file , process is not running.
         
     | 
| 
      
 83 
     | 
    
         
            +
                              execute :rm, fetch(:puma_pid)
         
     | 
| 
      
 84 
     | 
    
         
            +
                            end
         
     | 
| 
       78 
85 
     | 
    
         
             
                          else
         
     | 
| 
       79 
     | 
    
         
            -
                            # 
     | 
| 
       80 
     | 
    
         
            -
                             
     | 
| 
      
 86 
     | 
    
         
            +
                            #pid file not found, so puma is probably not running or it using another pidfile
         
     | 
| 
      
 87 
     | 
    
         
            +
                            warn 'Puma not running'
         
     | 
| 
       81 
88 
     | 
    
         
             
                          end
         
     | 
| 
       82 
     | 
    
         
            -
                        else
         
     | 
| 
       83 
     | 
    
         
            -
                          #pid file not found, so puma is probably not running or it using another pidfile
         
     | 
| 
       84 
     | 
    
         
            -
                          warn 'Puma not running'
         
     | 
| 
       85 
89 
     | 
    
         
             
                        end
         
     | 
| 
       86 
90 
     | 
    
         
             
                      end
         
     | 
| 
       87 
91 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -92,15 +96,17 @@ namespace :puma do 
     | 
|
| 
       92 
96 
     | 
    
         
             
              %w[phased-restart restart].map do |command|
         
     | 
| 
       93 
97 
     | 
    
         
             
                desc "#{command} puma"
         
     | 
| 
       94 
98 
     | 
    
         
             
                task command do
         
     | 
| 
       95 
     | 
    
         
            -
                  on roles (fetch(:puma_role)) do
         
     | 
| 
      
 99 
     | 
    
         
            +
                  on roles (fetch(:puma_role)) do |role|
         
     | 
| 
       96 
100 
     | 
    
         
             
                    within current_path do
         
     | 
| 
       97 
     | 
    
         
            -
                       
     | 
| 
       98 
     | 
    
         
            -
                         
     | 
| 
       99 
     | 
    
         
            -
                           
     | 
| 
       100 
     | 
    
         
            -
             
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                           
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
      
 101 
     | 
    
         
            +
                      puma_switch_user(role) do
         
     | 
| 
      
 102 
     | 
    
         
            +
                        with rack_env: fetch(:puma_env) do
         
     | 
| 
      
 103 
     | 
    
         
            +
                          if test "[ -f #{fetch(:puma_pid)} ]" and test "kill -0 $( cat #{fetch(:puma_pid)} )"
         
     | 
| 
      
 104 
     | 
    
         
            +
                            # NOTE pid exist but state file is nonsense, so ignore that case
         
     | 
| 
      
 105 
     | 
    
         
            +
                            execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}"
         
     | 
| 
      
 106 
     | 
    
         
            +
                          else
         
     | 
| 
      
 107 
     | 
    
         
            +
                            # Puma is not running or state file is not present : Run it
         
     | 
| 
      
 108 
     | 
    
         
            +
                            invoke 'puma:start'
         
     | 
| 
      
 109 
     | 
    
         
            +
                          end
         
     | 
| 
       104 
110 
     | 
    
         
             
                        end
         
     | 
| 
       105 
111 
     | 
    
         
             
                      end
         
     | 
| 
       106 
112 
     | 
    
         
             
                    end
         
     | 
| 
         @@ -129,7 +135,23 @@ namespace :puma do 
     | 
|
| 
       129 
135 
     | 
    
         
             
                end
         
     | 
| 
       130 
136 
     | 
    
         
             
              end
         
     | 
| 
       131 
137 
     | 
    
         | 
| 
      
 138 
     | 
    
         
            +
              def puma_switch_user(role, &block)
         
     | 
| 
      
 139 
     | 
    
         
            +
                user = puma_user(role)
         
     | 
| 
      
 140 
     | 
    
         
            +
                if user == role.user
         
     | 
| 
      
 141 
     | 
    
         
            +
                  block.call
         
     | 
| 
      
 142 
     | 
    
         
            +
                else
         
     | 
| 
      
 143 
     | 
    
         
            +
                  as user do
         
     | 
| 
      
 144 
     | 
    
         
            +
                    block.call
         
     | 
| 
      
 145 
     | 
    
         
            +
                  end
         
     | 
| 
      
 146 
     | 
    
         
            +
                end
         
     | 
| 
      
 147 
     | 
    
         
            +
              end
         
     | 
| 
       132 
148 
     | 
    
         | 
| 
      
 149 
     | 
    
         
            +
              def puma_user(role)
         
     | 
| 
      
 150 
     | 
    
         
            +
                properties = role.properties
         
     | 
| 
      
 151 
     | 
    
         
            +
                properties.fetch(:puma_user) ||               # local property for puma only
         
     | 
| 
      
 152 
     | 
    
         
            +
                properties.fetch(:run_as) || # global property across multiple capistrano gems
         
     | 
| 
      
 153 
     | 
    
         
            +
                role.user
         
     | 
| 
      
 154 
     | 
    
         
            +
              end
         
     | 
| 
       133 
155 
     | 
    
         | 
| 
       134 
156 
     | 
    
         
             
              def puma_workers
         
     | 
| 
       135 
157 
     | 
    
         
             
                fetch(:puma_workers, 0)
         
     | 
| 
         @@ -2,12 +2,14 @@ namespace :puma do 
     | 
|
| 
       2 
2 
     | 
    
         
             
              namespace :workers do
         
     | 
| 
       3 
3 
     | 
    
         
             
                desc 'Add a worker'
         
     | 
| 
       4 
4 
     | 
    
         
             
                task :count do
         
     | 
| 
       5 
     | 
    
         
            -
                  on roles (fetch(:puma_role)) do
         
     | 
| 
      
 5 
     | 
    
         
            +
                  on roles (fetch(:puma_role)) do |role|
         
     | 
| 
      
 6 
     | 
    
         
            +
                    puma_switch_user(role) do
         
     | 
| 
       6 
7 
     | 
    
         
             
                    #TODO
         
     | 
| 
       7 
8 
     | 
    
         
             
                    # cleanup
         
     | 
| 
       8 
9 
     | 
    
         
             
                    # add host name/ip
         
     | 
| 
       9 
10 
     | 
    
         
             
                    workers_count = capture("ps ax | grep -c 'puma: cluster worker: `cat  #{fetch(:puma_pid)}`'").to_i - 1
         
     | 
| 
       10 
11 
     | 
    
         
             
                    log  "Workers count : #{workers_count}"
         
     | 
| 
      
 12 
     | 
    
         
            +
                    end
         
     | 
| 
       11 
13 
     | 
    
         
             
                  end
         
     | 
| 
       12 
14 
     | 
    
         
             
                end
         
     | 
| 
       13 
15 
     | 
    
         | 
| 
         @@ -17,18 +19,20 @@ namespace :puma do 
     | 
|
| 
       17 
19 
     | 
    
         
             
                # Refactor
         
     | 
| 
       18 
20 
     | 
    
         
             
                desc 'Worker++'
         
     | 
| 
       19 
21 
     | 
    
         
             
                task :more do
         
     | 
| 
       20 
     | 
    
         
            -
                  on roles (fetch(:puma_role)) do
         
     | 
| 
       21 
     | 
    
         
            -
                     
     | 
| 
      
 22 
     | 
    
         
            +
                  on roles (fetch(:puma_role)) do |role|
         
     | 
| 
      
 23 
     | 
    
         
            +
                    puma_switch_user(role) do
         
     | 
| 
      
 24 
     | 
    
         
            +
                      execute("kill -TTIN `cat  #{fetch(:puma_pid)}`")
         
     | 
| 
      
 25 
     | 
    
         
            +
                    end
         
     | 
| 
       22 
26 
     | 
    
         
             
                  end
         
     | 
| 
       23 
27 
     | 
    
         
             
                end
         
     | 
| 
       24 
28 
     | 
    
         | 
| 
       25 
29 
     | 
    
         
             
                desc 'Worker--'
         
     | 
| 
       26 
30 
     | 
    
         
             
                task :less do
         
     | 
| 
       27 
     | 
    
         
            -
                  on roles (fetch(:puma_role)) do
         
     | 
| 
       28 
     | 
    
         
            -
                     
     | 
| 
      
 31 
     | 
    
         
            +
                  on roles (fetch(:puma_role)) do |role|
         
     | 
| 
      
 32 
     | 
    
         
            +
                    puma_switch_user(role) do
         
     | 
| 
      
 33 
     | 
    
         
            +
                      execute("kill -TTOU `cat  #{fetch(:puma_pid)}`")
         
     | 
| 
      
 34 
     | 
    
         
            +
                    end
         
     | 
| 
       29 
35 
     | 
    
         
             
                  end
         
     | 
| 
       30 
36 
     | 
    
         
             
                end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
37 
     | 
    
         
             
              end
         
     | 
| 
       34 
     | 
    
         
            -
            end
         
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -11,9 +11,22 @@ end 
     | 
|
| 
       11 
11 
     | 
    
         
             
            %><% @backends.each do |server|  %>
         
     | 
| 
       12 
12 
     | 
    
         
             
              <%= server %><% end %>
         
     | 
| 
       13 
13 
     | 
    
         
             
            }
         
     | 
| 
      
 14 
     | 
    
         
            +
            <% if fetch(:nginx_use_ssl) %>
         
     | 
| 
      
 15 
     | 
    
         
            +
            server {
         
     | 
| 
      
 16 
     | 
    
         
            +
              listen 80;
         
     | 
| 
      
 17 
     | 
    
         
            +
              rewrite ^(.*) https://$host$1 permanent;
         
     | 
| 
      
 18 
     | 
    
         
            +
            }
         
     | 
| 
      
 19 
     | 
    
         
            +
            <% end %>
         
     | 
| 
       14 
20 
     | 
    
         | 
| 
       15 
21 
     | 
    
         
             
            server {
         
     | 
| 
      
 22 
     | 
    
         
            +
            <% if fetch(:nginx_use_ssl) %>
         
     | 
| 
      
 23 
     | 
    
         
            +
              listen 443;
         
     | 
| 
      
 24 
     | 
    
         
            +
              ssl on;
         
     | 
| 
      
 25 
     | 
    
         
            +
              ssl_certificate /etc/ssl/certs/<%= fetch(:nginx_config_name) %>.crt;
         
     | 
| 
      
 26 
     | 
    
         
            +
              ssl_certificate_key /etc/ssl/private/<%= fetch(:nginx_config_name) %>.key;
         
     | 
| 
      
 27 
     | 
    
         
            +
            <% else %>
         
     | 
| 
       16 
28 
     | 
    
         
             
              listen 80;
         
     | 
| 
      
 29 
     | 
    
         
            +
            <% end %>
         
     | 
| 
       17 
30 
     | 
    
         | 
| 
       18 
31 
     | 
    
         
             
              client_max_body_size 4G;
         
     | 
| 
       19 
32 
     | 
    
         
             
              keepalive_timeout 10;
         
     | 
| 
         @@ -29,6 +42,9 @@ server { 
     | 
|
| 
       29 
42 
     | 
    
         
             
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         
     | 
| 
       30 
43 
     | 
    
         
             
                proxy_set_header Host $http_host;
         
     | 
| 
       31 
44 
     | 
    
         
             
                proxy_redirect off;
         
     | 
| 
      
 45 
     | 
    
         
            +
            <% if fetch(:nginx_use_ssl) %>
         
     | 
| 
      
 46 
     | 
    
         
            +
                proxy_set_header X-Forwarded-Proto https;
         
     | 
| 
      
 47 
     | 
    
         
            +
            <% end %>
         
     | 
| 
       32 
48 
     | 
    
         
             
                proxy_pass http://puma_<%= fetch(:nginx_config_name) %>;
         
     | 
| 
       33 
49 
     | 
    
         
             
                # limit_req zone=one;
         
     | 
| 
       34 
50 
     | 
    
         
             
                access_log <%= shared_path %>/log/nginx.access.log;
         
     | 
| 
         @@ -33,7 +33,7 @@ on_restart do 
     | 
|
| 
       33 
33 
     | 
    
         
             
              ENV["BUNDLE_GEMFILE"] = "<%= fetch(:bundle_gemfile, "#{current_path}/Gemfile") %>"
         
     | 
| 
       34 
34 
     | 
    
         
             
            end
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
            <% if fetch(:puma_init_active_record) %>
         
     | 
| 
      
 36 
     | 
    
         
            +
            <% if puma_preload_app? and fetch(:puma_init_active_record) %>
         
     | 
| 
       37 
37 
     | 
    
         
             
            on_worker_boot do
         
     | 
| 
       38 
38 
     | 
    
         
             
              ActiveSupport.on_load(:active_record) do
         
     | 
| 
       39 
39 
     | 
    
         
             
                ActiveRecord::Base.establish_connection
         
     | 
| 
         @@ -3,5 +3,5 @@ 
     | 
|
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            check process <%= puma_monit_service_name %>
         
     | 
| 
       5 
5 
     | 
    
         
             
              with pidfile "<%= fetch(:puma_pid) %>"
         
     | 
| 
       6 
     | 
    
         
            -
              start program = "/usr/bin/sudo -u <%= @role 
     | 
| 
       7 
     | 
    
         
            -
              stop program = "/usr/bin/sudo -u <%= @role 
     | 
| 
      
 6 
     | 
    
         
            +
              start program = "/usr/bin/sudo -u <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec puma -C <%= fetch(:puma_conf) %> --daemon'"
         
     | 
| 
      
 7 
     | 
    
         
            +
              stop program = "/usr/bin/sudo -u <%= puma_user(@role) %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec pumactl -S <%= fetch(:puma_state) %> stop'"
         
     | 
| 
         @@ -3,7 +3,7 @@ app=$1; 
     | 
|
| 
       3 
3 
     | 
    
         
             
            cd $app || exit 1
         
     | 
| 
       4 
4 
     | 
    
         | 
| 
       5 
5 
     | 
    
         
             
            if [ -e Gemfile ]; then
         
     | 
| 
       6 
     | 
    
         
            -
                exec sh -c "exec bundle exec puma -C  
     | 
| 
      
 6 
     | 
    
         
            +
                exec <%= fetch(:puma_user) ? "sudo -u #{puma_user(@role)}" : '' %> sh -c "exec bundle exec puma -C <%= fetch(:puma_conf) %> --daemon"
         
     | 
| 
       7 
7 
     | 
    
         
             
            else
         
     | 
| 
       8 
     | 
    
         
            -
                exec sh -c "exec puma -C  
     | 
| 
      
 8 
     | 
    
         
            +
                exec <%= fetch(:puma_user) ? "sudo -u #{puma_user(@role)}" : '' %> sh -c "exec puma -C <%= fetch(:puma_conf) %> --daemon"
         
     | 
| 
       9 
9 
     | 
    
         
             
            fi
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: capistrano3-puma
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.2.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Abdelkader Boudih
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2015- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2015-08-19 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: capistrano
         
     | 
| 
         @@ -57,11 +57,11 @@ files: 
     | 
|
| 
       57 
57 
     | 
    
         
             
            - lib/capistrano/puma/nginx.rb
         
     | 
| 
       58 
58 
     | 
    
         
             
            - lib/capistrano/puma/version.rb
         
     | 
| 
       59 
59 
     | 
    
         
             
            - lib/capistrano/puma/workers.rb
         
     | 
| 
       60 
     | 
    
         
            -
            - lib/capistrano/tasks/jungle. 
     | 
| 
       61 
     | 
    
         
            -
            - lib/capistrano/tasks/monit. 
     | 
| 
       62 
     | 
    
         
            -
            - lib/capistrano/tasks/nginx. 
     | 
| 
       63 
     | 
    
         
            -
            - lib/capistrano/tasks/puma. 
     | 
| 
       64 
     | 
    
         
            -
            - lib/capistrano/tasks/workers. 
     | 
| 
      
 60 
     | 
    
         
            +
            - lib/capistrano/tasks/jungle.rake
         
     | 
| 
      
 61 
     | 
    
         
            +
            - lib/capistrano/tasks/monit.rake
         
     | 
| 
      
 62 
     | 
    
         
            +
            - lib/capistrano/tasks/nginx.rake
         
     | 
| 
      
 63 
     | 
    
         
            +
            - lib/capistrano/tasks/puma.rake
         
     | 
| 
      
 64 
     | 
    
         
            +
            - lib/capistrano/tasks/workers.rake
         
     | 
| 
       65 
65 
     | 
    
         
             
            - lib/capistrano/templates/nginx_conf.erb
         
     | 
| 
       66 
66 
     | 
    
         
             
            - lib/capistrano/templates/puma-deb.erb
         
     | 
| 
       67 
67 
     | 
    
         
             
            - lib/capistrano/templates/puma-rpm.erb
         
     | 
| 
         @@ -1,10 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            namespace :puma do
         
     | 
| 
       2 
     | 
    
         
            -
              desc "Setup nginx configuration"
         
     | 
| 
       3 
     | 
    
         
            -
              task :nginx_config do
         
     | 
| 
       4 
     | 
    
         
            -
                on roles(fetch(:puma_nginx, :web)) do |role|
         
     | 
| 
       5 
     | 
    
         
            -
                  template_puma("nginx_conf", "/tmp/nginx_#{fetch(:nginx_config_name)}", role)
         
     | 
| 
       6 
     | 
    
         
            -
                  sudo :mv, "/tmp/nginx_#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)}"
         
     | 
| 
       7 
     | 
    
         
            -
                  sudo :ln, '-fs', "#{fetch(:nginx_sites_available_path)}/#{fetch(:nginx_config_name)} #{fetch(:nginx_sites_enabled_path)}/#{fetch(:nginx_config_name)}"
         
     | 
| 
       8 
     | 
    
         
            -
                end
         
     | 
| 
       9 
     | 
    
         
            -
              end
         
     | 
| 
       10 
     | 
    
         
            -
            end
         
     |