capistrano3-puma 1.1.0 → 1.2.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: a285319ce829244caa77fe60b0e120c41c7b07f8
4
- data.tar.gz: 848e536e6d08bea1207b12ba4e01b632128efe0e
3
+ metadata.gz: 1755f57fc22107e5f701181029fdfb83c371f812
4
+ data.tar.gz: 9366f5b212d65fe58f2e9fca81ea523add36636b
5
5
  SHA512:
6
- metadata.gz: b4ea06110afed0438c01329a8720fc85a99e4e6064060dde896cd2fdf4028a0a2ac76380e111febc3ec7feac0b1b1025c434e5968e6f12e077de8d4e0f2f3168
7
- data.tar.gz: 4841fbeb5154fd76a6f2b44673ccb99cd695b6a2000366071c00d6553a96e3eaa7f3b2e8e41344e0b84c36f77e1d17c03b60015390268b33c2cdae9383671c41
6
+ metadata.gz: feccecc2474ff21ef7573ceed1fb04c050e24fb4c7be308842ca3cfc56fd9979bfd491f7c1334091dba292e34ba159692ca27d4901afec7bcc6c2a8b7f67ba8e
7
+ data.tar.gz: d9d1bc5fdcefb10fc9d9b594febec02baca91d0de3093425e274a2e9e4211a1ec86789328afb6d90617787ff2701b7fe10b793cfb1299b5b46256f8257f2cd45
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2013-2014 Abdelkader Boudih
3
+ Copyright (c) 2013-2015 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
@@ -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
 
@@ -1 +1 @@
1
- load File.expand_path('../tasks/puma.cap', __FILE__)
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.cap', __FILE__)
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.cap', __FILE__)
2
+ load File.expand_path('../../tasks/monit.rake', __FILE__)
@@ -1 +1 @@
1
- load File.expand_path('../../tasks/nginx.cap', __FILE__)
1
+ load File.expand_path('../../tasks/nginx.rake', __FILE__)
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Puma
3
- VERSION = '1.1.0'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -1,2 +1,2 @@
1
1
  # Load monit tasks
2
- load File.expand_path('../../tasks/workers.cap', __FILE__)
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 :puma_monit_bin, -> { "/usr/bin/monit" }
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
- sudo "mv #{fetch(:tmp_dir)}/monit.conf #{fetch(:puma_monit_conf_dir)}"
17
- sudo "#{fetch(:puma_monit_bin)} reload"
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
- sudo "#{fetch(:puma_monit_bin)} monitor #{puma_monit_service_name}"
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
- sudo "#{fetch(:puma_monit_bin)} unmonitor #{puma_monit_service_name}"
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
- sudo "#{fetch(:puma_monit_bin)} start #{puma_monit_service_name}"
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
- sudo "#{fetch(:puma_monit_bin)} stop #{puma_monit_service_name}"
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
- sudo "#{fetch(:puma_monit_bin)} restart #{puma_monit_service_name}"
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
- if test "[ -f #{fetch(:puma_conf)} ]"
56
- info "using conf file #{fetch(:puma_conf)}"
57
- else
58
- invoke 'puma:config'
59
- end
60
- within current_path do
61
- with rack_env: fetch(:puma_env) do
62
-
63
- execute :bundle, 'exec', :puma, "-C #{fetch(:puma_conf)} --daemon"
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
- with rack_env: fetch(:puma_env) do
75
- if test "[ -f #{fetch(:puma_pid)} ]"
76
- if test "kill -0 $( cat #{fetch(:puma_pid)} )"
77
- execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}"
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
- # delete invalid pid file , process is not running.
80
- execute :rm, fetch(:puma_pid)
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
- with rack_env: fetch(:puma_env) do
98
- if test "[ -f #{fetch(:puma_pid)} ]" and test "kill -0 $( cat #{fetch(:puma_pid)} )"
99
- # NOTE pid exist but state file is nonsense, so ignore that case
100
- execute :bundle, 'exec', :pumactl, "-S #{fetch(:puma_state)} #{command}"
101
- else
102
- # Puma is not running or state file is not present : Run it
103
- invoke 'puma:start'
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
- execute("kill -TTIN `cat #{fetch(:puma_pid)}`")
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
- execute("kill -TTOU `cat #{fetch(:puma_pid)}`")
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.user %> /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 <%= @role.user %> /bin/bash -c 'cd <%= current_path %> && <%= SSHKit.config.command_map[:bundle] %> exec pumactl -S <%= fetch(:puma_state) %> stop'"
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 ../../shared/puma.rb --daemon"
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 ../../shared/puma.rb --daemon"
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.1.0
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-06-23 00:00:00.000000000 Z
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.cap
61
- - lib/capistrano/tasks/monit.cap
62
- - lib/capistrano/tasks/nginx.cap
63
- - lib/capistrano/tasks/puma.cap
64
- - lib/capistrano/tasks/workers.cap
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