capistrano-generals 0.1.0 → 0.1.1

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: 24b9088cc96674dce692f1d35bbe6c7e402ef8d7
4
- data.tar.gz: e0c51c91fbaa60908ec4fa6f28acad18d7145f2f
3
+ metadata.gz: ce4edad6fe2a55d648cc2d1cd94efb7990d316ba
4
+ data.tar.gz: 4f583f9e7c648daafc2d38b57af1f82b5d2e409a
5
5
  SHA512:
6
- metadata.gz: 908f1e6c07c640d16f262a68bde17787d54a7d3a4fc428bc6df889e291ebd0223da58d634f5c7b08faf28785a47e8a48167b33bf7b036af7070697c96e011c8d
7
- data.tar.gz: d9333ace8a8bec85752d387168a89a065caa5b7e71adb5f1161a9965e00052d59fcc26be10a47424d699f66b2db42788538f013020826e67d980a3d386b96bfe
6
+ metadata.gz: c4996378b3e7964dae3ca0d761e29d6f53e6cc27cfee034de5d8e3bf75c19cc6bae6cb81b86c50913d1c457b51a1811dfd0d2b8fc5257ead6f7933b368749551
7
+ data.tar.gz: 73628d76d1b34286d780fcb4ac5be17504fd9f2a14082c78a8d2dbd08d8c99b8e0b59fb54ed9e6f4a143c9dcc161cbc6a121b879e5cd9f78b8753384829fe634
data/README.md CHANGED
@@ -86,4 +86,6 @@ This will upgrade the unicorn workers and restart nginx.
86
86
 
87
87
 
88
88
  ## Disclaimer
89
- With ideas from: https://github.com/capistrano-plugins/capistrano-unicorn-nginx
89
+ With ideas from:
90
+ * https://github.com/capistrano-plugins/capistrano-unicorn-nginx
91
+ * https://exceptiontrap.com/blog/11-create-and-install-ssl-certificates-with-ease-capistrano-recipe
@@ -14,19 +14,6 @@ module Capistrano
14
14
  "#{fetch(:nginx_location)}/sites-enabled/#{fetch(:app_config_name)}"
15
15
  end
16
16
 
17
- # ssl related files
18
- def nginx_ssl_cert_file
19
- "/etc/ssl/certs/#{fetch(:nginx_ssl_cert)}"
20
- end
21
-
22
- def nginx_ssl_cert_key_file
23
- "/etc/ssl/private/#{fetch(:nginx_ssl_cert_key)}"
24
- end
25
-
26
- def nginx_ssl_dhparam_file
27
- "/etc/ssl/certs/#{fetch(:nginx_ssl_dhparam)}"
28
- end
29
-
30
17
  end
31
18
  end
32
19
  end
@@ -0,0 +1,22 @@
1
+ module Capistrano
2
+ module DSL
3
+ module PumaPaths
4
+
5
+ def puma_service
6
+ "puma_#{fetch(:app_config_name)}"
7
+ end
8
+
9
+ def puma_initd_file
10
+ "/etc/init.d/#{puma_service}"
11
+ end
12
+
13
+ def puma_default_config_file
14
+ shared_path.join('config/puma.rb')
15
+ end
16
+
17
+ def puma_default_pid_file
18
+ shared_path.join('tmp/pids/puma.pid')
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,47 @@
1
+ module Capistrano
2
+ module DSL
3
+ module SSLPaths
4
+
5
+ # Get the full path of a certificate file
6
+ def certificate_file_for(filename)
7
+ File.expand_path(filename, fetch(:local_certs_folder))
8
+ end
9
+
10
+ def existing_certificate_file_for(filename)
11
+ filename = certificate_file_for filename
12
+ unless File.exists? filename
13
+ abort red "Could not find #{filename}"
14
+ end
15
+ filename
16
+ end
17
+
18
+ def new_certificate_file_for(filename)
19
+ filename = certificate_file_for filename
20
+ if File.exists? filename
21
+ abort red "File #{filename} already exists"
22
+ end
23
+ execute :mkdir, '-pv', fetch(:local_certs_folder)
24
+ filename
25
+ end
26
+
27
+ def chained_certificate
28
+ c1 = File.read(existing_certificate_file_for(fetch(:ssl_cert)))
29
+ c2 = File.read(existing_certificate_file_for(fetch(:ssl_cert_intermediate)))
30
+ StringIO.new(c1.rstrip + "\n" + c2)
31
+ end
32
+
33
+ # ssl related files
34
+ def remote_ssl_cert_chained_file
35
+ "#{fetch(:remote_certs_folder)}/certs/#{fetch(:ssl_cert_chain)}"
36
+ end
37
+
38
+ def remote_ssl_cert_key_file
39
+ "#{fetch(:remote_certs_folder)}/private/#{fetch(:ssl_cert_key)}"
40
+ end
41
+
42
+ def remote_ssl_dhparam_file
43
+ "#{fetch(:remote_certs_folder)}/certs/#{fetch(:ssl_dhparam)}"
44
+ end
45
+ end
46
+ end
47
+ end
@@ -10,6 +10,10 @@ module Capistrano
10
10
  SSHKit::Command.new(:bundle, :exec, :sidekiq, args).to_command
11
11
  end
12
12
 
13
+ def bundle_puma(*args)
14
+ SSHKit::Command.new(:bundle, :exec, :puma, args).to_command
15
+ end
16
+
13
17
  def red text
14
18
  "\033[31m#{text}\033[0m"
15
19
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module Generals
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -13,30 +13,51 @@ namespace :load do
13
13
  set :nginx_location, '/etc/nginx'
14
14
  set :nginx_redirect_www, true
15
15
  set :nginx_fail_timeout, 0
16
+ set :nginx_x_frame_options, 'DENY'
17
+ set :ngingx_strict_transport_security, true
18
+ set :nginx_respond_to_subdomains, false
16
19
 
17
- # SSL Settings
20
+ # Nginx ssl settings
18
21
  set :nginx_use_ssl, false
19
22
  set :nginx_ssl_stapling, true
20
23
  set :nginx_ssl_ciphers, 'AES128+EECDH:AES128+EDH:!aNULL'
21
24
  set :nginx_ssl_protocols, 'TLSv1 TLSv1.1 TLSv1.2'
22
25
  set :nginx_ssl_session_cache, 'shared:SSL:10m'
23
- set :nginx_ssl_cert, -> { "#{fetch(:server_domain)}.crt" }
24
- set :nginx_ssl_cert_key, -> { "#{fetch(:server_domain)}.key" }
25
- set :nginx_ssl_dhparam, 'dhparam.pem'
26
- set :nginx_server_ciphers, false
27
- set :nginx_server_ciphers_path, '/etc/ssl/certs/dhparam.pem'
26
+
27
+ # SSL Settings
28
+ set :local_certs_folder, 'config/deploy/certs'
29
+ set :remote_certs_folder, '/etc/ssl'
30
+ set :ssl_csr, -> { "#{fetch(:server_domain)}.csr" }
31
+ set :ssl_cert, -> { "#{fetch(:server_domain)}.crt" }
32
+ set :ssl_cert_intermediate, -> { "#{fetch(:server_domain)}-intermediate.crt" }
33
+ set :ssl_cert_chain, -> { "#{fetch(:server_domain)}-chained.crt" }
34
+ set :ssl_cert_key, -> { "#{fetch(:server_domain)}.key" }
35
+ set :ssl_server_ciphers, false
36
+ set :ssl_dhparam, 'dhparam.pem'
28
37
 
29
38
  # General Unicorn settings
30
39
  set :unicorn_pid, -> { unicorn_default_pid_file } # shared_path/tmp/pids/unicorn.pid
31
40
  set :unicorn_config, -> { unicorn_default_config_file } # shared_path/config/unicorn.rb
32
41
  set :unicorn_workers, 2
33
42
  set :unicorn_worker_timeout, 30
34
- set :unicorn_log, 'unicorn.stdout.log'
35
- set :unicorn_error_log, 'unicorn.stderr.log'
43
+ set :unicorn_log, 'unicorn.log'
44
+ set :unicorn_error_log, 'unicorn.log'
36
45
  set :unicorn_user, -> { fetch(:deploy_user) }
37
46
  set :unicorn_env, ''
38
47
  set :unicorn_app_env, -> { fetch(:rails_env) || fetch(:rack_env) || fetch(:stage) }
39
48
 
49
+ # General Puma settings
50
+ set :puma_preload_app, true
51
+ set :puma_pid, -> { puma_default_pid_file } # shared_path/tmp/pids/puma.pid
52
+ set :puma_config, -> { puma_default_config_file } # shared_path/config/puma.rb
53
+ set :puma_workers, 2
54
+ set :puma_worker_timeout, 30
55
+ set :puma_min_threads, 0
56
+ set :puma_max_threads, 16
57
+ set :puma_user, -> { fetch(:deploy_user) }
58
+ set :puma_env, ''
59
+ set :puma_app_env, -> { fetch(:rails_env) || fetch(:rack_env) || fetch(:stage) }
60
+
40
61
  # General Sidekiq settings
41
62
  set :sidekiq_workers, 3
42
63
  set :sidekiq_user, -> { fetch(:deploy_user) }
@@ -1,5 +1,7 @@
1
1
  require 'capistrano/dsl/nginx_paths'
2
2
  include Capistrano::DSL::NginxPaths
3
+ require 'capistrano/dsl/ssl_paths'
4
+ include Capistrano::DSL::SSLPaths
3
5
 
4
6
  namespace :nginx do
5
7
 
@@ -52,7 +54,7 @@ namespace :nginx do
52
54
  end
53
55
 
54
56
  namespace :deploy do
55
- after :publishing, 'nginx:reload'
57
+ after :publishing, 'nginx:restart'
56
58
  end
57
59
 
58
60
  desc 'Server setup tasks'
@@ -0,0 +1,81 @@
1
+ require 'capistrano/dsl/puma_paths'
2
+ include Capistrano::DSL::PumaPaths
3
+
4
+ namespace :puma do
5
+
6
+ desc 'Test capistrano config setup'
7
+ task :capistrano_config_test do
8
+ raise 'Use puma is not set as the application runner' unless fetch(:use_puma)
9
+ raise 'Unicorn is also set as application runner' if fetch(:use_unicorn)
10
+ raise 'Set the puma_user, which is default the deploy_user' unless fetch(:puma_user)
11
+ raise 'Set server_domain variable to setup nginx' unless fetch(:server_domain)
12
+ end
13
+
14
+ desc 'Setup Puma initializer'
15
+ task :setup_initializer do
16
+ on roles :app do
17
+ sudo_upload! template('puma_init.sh'), puma_initd_file
18
+ execute :chmod, '+x', puma_initd_file
19
+ sudo 'update-rc.d', '-f', puma_service, 'defaults'
20
+ end
21
+ end
22
+ before :setup_initializer, :capistrano_config_test
23
+
24
+ desc 'Setup puma app configuration'
25
+ task :setup_app_config do
26
+ on roles :app do
27
+ execute :mkdir, '-pv', File.dirname(fetch(:puma_config).to_s)
28
+ upload! template('puma.rb'), fetch(:puma_config).to_s
29
+ end
30
+ end
31
+ before :setup_app_config, :capistrano_config_test
32
+
33
+ desc 'Setup puma'
34
+ task :setup do
35
+ if fetch :use_puma
36
+ invoke 'puma:setup_initializer'
37
+ invoke 'puma:setup_app_config'
38
+ end
39
+ end
40
+
41
+ desc 'Start puma'
42
+ task :start do
43
+ on roles :app do
44
+ sudo puma_initd_file, 'start'
45
+ end
46
+ end
47
+ before :start, :capistrano_config_test
48
+
49
+ desc 'Stop puma'
50
+ task :stop do
51
+ on roles :app do
52
+ execute puma_initd_file, 'stop'
53
+ sleep 3
54
+ end
55
+ end
56
+ before :stop, :capistrano_config_test
57
+
58
+ desc 'Restart puma'
59
+ task :restart do
60
+ invoke 'puma:stop'
61
+ invoke 'puma:start'
62
+ end
63
+ before :restart, :capistrano_config_test
64
+
65
+ desc 'Restarts puma if puma enabled'
66
+ task :after_publishing do
67
+ if fetch :use_puma
68
+ invoke 'puma:restart'
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ namespace :deploy do
75
+ after :publishing, 'puma:after_publishing'
76
+ end
77
+
78
+ desc 'Server setup tasks'
79
+ task :setup do
80
+ invoke 'puma:setup'
81
+ end
@@ -13,43 +13,56 @@ namespace :sidekiq do
13
13
  on roles :app do
14
14
  sudo_upload! template('sidekiq_init.sh'), sidekiq_initd_file
15
15
  execute :chmod, '+x', sidekiq_initd_file
16
- sudo 'update-rc.d', '-f', unicorn_service, 'defaults'
16
+ sudo 'update-rc.d', '-f', sidekiq_service, 'defaults'
17
17
  end
18
18
  end
19
19
  before :setup_initializer, :capistrano_config_test
20
20
 
21
+ desc 'Setup Sidekiq'
22
+ task :setup do
23
+ if fetch :use_sidekiq
24
+ invoke 'sidekiq:setup_initializer'
25
+ end
26
+ end
27
+
21
28
  desc 'Start sidekiq'
22
29
  task :start do
23
- on roles(:app) do
24
- execute "sudo /etc/init.d/sidekiq_#{fetch(:application)}_#{fetch(:stage)} start"
30
+ on roles :app do
31
+ sudo sidekiq_initd_file, 'start'
25
32
  end
26
33
  end
34
+ before :start, :capistrano_config_test
27
35
 
28
36
  desc 'Stop sidekiq'
29
37
  task :stop do
30
- on roles(:app) do
31
- execute "sudo /etc/init.d/sidekiq_#{fetch(:application)}_#{fetch(:stage)} stop"
38
+ on roles :app do
39
+ sudo sidekiq_initd_file, 'stop'
32
40
  sleep 8
33
41
  end
34
42
  end
43
+ before :stop, :capistrano_config_test
35
44
 
36
45
  desc 'Restart sidekiq'
37
46
  task :restart do
38
47
  invoke 'sidekiq:stop'
39
48
  invoke 'sidekiq:start'
40
49
  end
50
+ before :restart, :capistrano_config_test
51
+
52
+ desc 'Restarts sidekiq if sidekiq enabled'
53
+ task :after_publishing do
54
+ if fetch :use_sidekiq
55
+ invoke 'sidekiq:restart'
56
+ end
57
+ end
41
58
 
42
59
  end
43
60
 
44
61
  namespace :deploy do
45
- if fetch(:use_sidekiq)
46
- after :publishing, 'sidekiq:restart'
47
- end
62
+ after :publishing, 'sidekiq:after_publishing'
48
63
  end
49
64
 
50
65
  desc 'Server setup tasks'
51
66
  task :setup do
52
- if fetch(:use_sidekiq)
53
- invoke 'unicorn:setup_initializer'
54
- end
67
+ invoke 'sidekiq:setup'
55
68
  end
@@ -0,0 +1,41 @@
1
+ require 'capistrano/dsl/ssl_paths'
2
+ include Capistrano::DSL::SSLPaths
3
+
4
+ namespace :ssl do
5
+ # If you intend to secure the URL https://www.yourdomain.com, then your CSR's common name must be www.yourdomain.com. If you plan on getting a wildcard certificate make sure to prefix your domain with an asterisk, example: *.domain.com.
6
+ desc 'Generate Private Key and CSR files'
7
+ task :generate_private_key_and_csr do
8
+ run_locally do
9
+ `openssl req -nodes -newkey rsa:2048 -sha256 -keyout #{new_certificate_file_for(fetch(:ssl_cert_key))} -out #{new_certificate_file_for(fetch(:ssl_csr))}`
10
+ end
11
+ end
12
+
13
+ desc 'Generate dhparam file'
14
+ task :generate_dhparam do
15
+ run_locally do
16
+ `openssl dhparam -out #{new_certificate_file_for(fetch(:ssl_dhparam))} 4096`
17
+ end
18
+ end
19
+
20
+ desc 'Send certificate and key to server'
21
+ task :upload do
22
+ on roles :web do
23
+ # Upload chained certificate
24
+ sudo_upload! chained_certificate, remote_ssl_cert_chained_file
25
+ sudo :chown, 'root', remote_ssl_cert_chained_file
26
+ sudo :chmod, '644', remote_ssl_cert_chained_file
27
+
28
+ # Upload key
29
+ sudo_upload! existing_certificate_file_for(fetch(:ssl_cert_key)), remote_ssl_cert_key_file
30
+ sudo :chown, 'root:ssl-cert', remote_ssl_cert_key_file
31
+ sudo :chmod, '640', remote_ssl_cert_key_file
32
+
33
+ # Upload dhparam
34
+ if File.exists? certificate_file_for(fetch(:ssl_dhparam))
35
+ sudo_upload! certificate_file_for(fetch(:ssl_dhparam)), remote_ssl_dhparam_file
36
+ sudo :chown, 'root', remote_ssl_dhparam_file
37
+ sudo :chmod, '644', remote_ssl_dhparam_file
38
+ end
39
+ end
40
+ end
41
+ end
@@ -30,12 +30,21 @@ namespace :unicorn do
30
30
  end
31
31
  before :setup_app_config, :capistrano_config_test
32
32
 
33
+ desc 'Setup unicorn'
34
+ task :setup do
35
+ if fetch :use_unicorn
36
+ invoke 'unicorn:setup_app_config'
37
+ invoke 'unicorn:setup_initializer'
38
+ end
39
+ end
40
+
33
41
  desc 'Start unicorn'
34
42
  task :start do
35
43
  on roles :app do
36
44
  sudo unicorn_initd_file, 'start'
37
45
  end
38
46
  end
47
+ before :start, :capistrano_config_test
39
48
 
40
49
  desc 'Stop unicorn'
41
50
  task :stop do
@@ -44,25 +53,29 @@ namespace :unicorn do
44
53
  sleep 3
45
54
  end
46
55
  end
56
+ before :stop, :capistrano_config_test
47
57
 
48
58
  desc 'Restart unicorn'
49
59
  task :restart do
50
60
  invoke 'unicorn:stop'
51
61
  invoke 'unicorn:start'
52
62
  end
63
+ before :restart, :capistrano_config_test
64
+
65
+ desc 'Restarts unicorn if puma enabled'
66
+ task :after_publishing do
67
+ if fetch :use_unicorn
68
+ invoke 'unicorn:restart'
69
+ end
70
+ end
53
71
 
54
72
  end
55
73
 
56
74
  namespace :deploy do
57
- if fetch(:use_unicorn)
58
- after :publishing, 'unicorn:restart'
59
- end
75
+ after :publishing, 'unicorn:after_publishing'
60
76
  end
61
77
 
62
78
  desc 'Server setup tasks'
63
79
  task :setup do
64
- if fetch(:use_unicorn)
65
- invoke 'unicorn:setup_app_config'
66
- invoke 'unicorn:setup_initializer'
67
- end
80
+ invoke 'unicorn:setup'
68
81
  end
@@ -0,0 +1,18 @@
1
+ module Capistrano
2
+ module Generals
3
+ module Generators
4
+ class PumaGenerator < Rails::Generators::Base
5
+ desc 'Create local puma configuration files for customization'
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :templates_path, type: :string,
8
+ default: 'config/deploy/templates',
9
+ banner: 'path to templates'
10
+
11
+ def copy_template
12
+ copy_file 'puma.rb.erb', "#{templates_path}/puma.rb.erb"
13
+ copy_file 'puma_init.sh.erb', "#{templates_path}/puma_init.sh.erb"
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module Capistrano
2
+ module Generals
3
+ module Generators
4
+ class SidekiqGenerator < Rails::Generators::Base
5
+ desc 'Create local sidekiq configuration file for customization'
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :templates_path, type: :string,
8
+ default: 'config/deploy/templates',
9
+ banner: 'path to templates'
10
+
11
+ def copy_template
12
+ copy_file 'sidekiq_init.sh.erb', "#{templates_path}/sidekiq_init.sh.erb"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -24,7 +24,7 @@ server {
24
24
  <% if fetch(:nginx_use_ssl) %>
25
25
  server {
26
26
  listen 80;
27
- server_name <%= fetch(:server_domain) %>;
27
+ server_name <%= "*.#{fetch(:server_domain)}" if fetch(:nginx_respond_to_subdomains) %> <%= fetch(:server_domain) %>;
28
28
  rewrite ^(.*) https://$host$1 permanent;
29
29
  }
30
30
  <% end %>
@@ -32,7 +32,7 @@ server {
32
32
  # Server
33
33
  ##############################
34
34
  server {
35
- server_name <%= fetch(:server_domain) %>;
35
+ server_name <%= "*.#{fetch(:server_domain)}" if fetch(:nginx_respond_to_subdomains) %> <%= fetch(:server_domain) %>;
36
36
  root <%= current_path %>/public;
37
37
 
38
38
  client_max_body_size 4G;
@@ -40,11 +40,11 @@ server {
40
40
 
41
41
  error_page 500 502 504 /500.html;
42
42
 
43
- # SSL Settings
44
43
  <% if fetch(:nginx_use_ssl) %>
44
+ # SSL Settings
45
45
  listen 443 ssl;
46
- ssl_certificate <%= nginx_ssl_cert_file %>;
47
- ssl_certificate_key <%= nginx_ssl_cert_key_file %>;
46
+ ssl_certificate <%= remote_ssl_cert_chained_file %>;
47
+ ssl_certificate_key <%= remote_ssl_cert_key_file %>;
48
48
 
49
49
  ssl_ciphers <%= fetch(:nginx_ssl_ciphers) %>;
50
50
  ssl_protocols <%= fetch(:nginx_ssl_protocols) %>;
@@ -57,15 +57,22 @@ server {
57
57
  resolver_timeout 10s;
58
58
  <% end %>
59
59
 
60
- <% if fetch(:nginx_server_ciphers) %>
60
+ <% if fetch(:ssl_server_ciphers) %>
61
61
  ssl_prefer_server_ciphers on;
62
- ssl_dhparam <%= nginx_ssl_dhparam_file %>;
62
+ ssl_dhparam <%= remote_ssl_dhparam_file %>;
63
63
  <% end %>
64
64
 
65
65
  <% else %>
66
66
  listen 80;
67
67
  <% end %>
68
68
 
69
+ <% if fetch(:ngingx_strict_transport_security) %>
70
+ add_header Strict-Transport-Security max-age=63072000;
71
+ add_header X-Content-Type-Options nosniff;
72
+ <% end %>
73
+ add_header X-Frame-Options <%= fetch(:nginx_x_frame_options) %>;
74
+
75
+
69
76
  <% # FILE HANDLING %>
70
77
  <% if fetch(:use_unicorn) %>
71
78
  try_files $uri/index.html $uri @unicorn_<%= fetch(:app_config_name) %>;
@@ -84,7 +91,7 @@ server {
84
91
  <% if fetch(:use_puma) %>
85
92
  try_files $uri/index.html $uri @puma_<%= fetch(:app_config_name) %>;
86
93
 
87
- location @unicorn_<%= fetch(:app_config_name) %> {
94
+ location @puma_<%= fetch(:app_config_name) %> {
88
95
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
89
96
  proxy_set_header Host $http_host;
90
97
  proxy_redirect off;
@@ -92,7 +99,7 @@ server {
92
99
  proxy_set_header X-Forwarded-Proto https;
93
100
  <% end %>
94
101
  proxy_pass http://puma_<%= fetch(:app_config_name) %>;
95
- }
102
+ }
96
103
  <% end %>
97
104
 
98
105
  location ~* ^/assets/ {
@@ -0,0 +1,22 @@
1
+ <%= template_to_s('_head').to_s %>
2
+ environment "<%= fetch(:puma_app_env) %>"
3
+ bind "unix:///tmp/puma.<%= fetch(:app_config_name) %>.sock"
4
+
5
+ threads <%= fetch(:puma_min_threads) %>, <%= fetch(:puma_max_threads) %>
6
+ workers <%= fetch(:puma_workers) %>
7
+
8
+ <% if fetch(:puma_preload_app) %>
9
+ preload_app!
10
+ <% end %>
11
+
12
+ worker_timeout <%= fetch(:puma_worker_timeout) %>
13
+
14
+ on_worker_boot do
15
+ if defined? ActiveSupport
16
+ ActiveSupport.on_load(:active_record) do
17
+ if defined? ActiveRecord::Base
18
+ ActiveRecord::Base.establish_connection
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,58 @@
1
+ #! /bin/sh
2
+ <%= template_to_s('_head').to_s %>
3
+ ### BEGIN INIT INFO
4
+ # Provides: puma
5
+ # Required-Start: $remote_fs $syslog
6
+ # Required-Stop: $remote_fs $syslog
7
+ # Default-Start: 2 3 4 5
8
+ # Default-Stop: 0 1 6
9
+ # Short-Description: Manage puma
10
+ # Description: Starts and Stops puma
11
+ ### END INIT INFO
12
+ set -e
13
+
14
+ # Feel free to change any of the following variables for your app:
15
+ APP_ROOT=<%= current_path %>
16
+ PID=<%= fetch(:puma_pid) %>
17
+ AS_USER=<%= fetch(:puma_user) %>
18
+ PUMA_ENV="<%= fetch(:puma_env) %>"
19
+ CMD="export HOME; true "${HOME:=$(getent passwd "$AS_USER" | cut -d: -f6;)}"; cd $APP_ROOT && $PUMA_ENV <%= bundle_puma('-d -C', fetch(:puma_config)) %>"
20
+
21
+ set -u
22
+
23
+ OLD_PIN="$PID.oldbin"
24
+
25
+ sig () {
26
+ test -s "$PID" && kill -$1 `cat $PID`
27
+ }
28
+
29
+ oldsig () {
30
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
31
+ }
32
+
33
+ run () {
34
+ if [ "$(id -un)" = "$AS_USER" ]; then
35
+ eval $1
36
+ else
37
+ su -c "$1" - $AS_USER
38
+ fi
39
+ }
40
+
41
+ case "$1" in
42
+ start)
43
+ sig 0 && echo >&2 "Already running" && exit 0
44
+ run "$CMD"
45
+ ;;
46
+ stop)
47
+ sig QUIT && exit 0
48
+ echo >&2 "Not running"
49
+ ;;
50
+ force-stop)
51
+ sig TERM && exit 0
52
+ echo >&2 "Not running"
53
+ ;;
54
+ *)
55
+ echo >&2 "Usage: $0 <start|stop|force-stop>"
56
+ exit 1
57
+ ;;
58
+ esac
@@ -7,7 +7,7 @@
7
7
  # Default-Start: 2 3 4 5
8
8
  # Default-Stop: 0 1 6
9
9
  # Short-Description: Manage sidekiq workers
10
- # Description: tarts and Stops Sidekiq message processor for Stratus application.
10
+ # Description: Starts and Stops Sidekiq message processor for Stratus application.
11
11
  ### END INIT INFO
12
12
 
13
13
  # User-specified exit parameters used in this script:
@@ -2,7 +2,7 @@ module Capistrano
2
2
  module Generals
3
3
  module Generators
4
4
  class UnicornGenerator < Rails::Generators::Base
5
- desc 'Create local unicorn configuration file for customization'
5
+ desc 'Create local unicorn configuration files for customization'
6
6
  source_root File.expand_path('../templates', __FILE__)
7
7
  argument :templates_path, type: :string,
8
8
  default: 'config/deploy/templates',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-generals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stef Schenkelaars
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-16 00:00:00.000000000 Z
11
+ date: 2015-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -67,7 +67,9 @@ files:
67
67
  - capistrano-generals.gemspec
68
68
  - lib/capistrano-generals.rb
69
69
  - lib/capistrano/dsl/nginx_paths.rb
70
+ - lib/capistrano/dsl/puma_paths.rb
70
71
  - lib/capistrano/dsl/sidekiq_paths.rb
72
+ - lib/capistrano/dsl/ssl_paths.rb
71
73
  - lib/capistrano/dsl/unicorn_paths.rb
72
74
  - lib/capistrano/generals.rb
73
75
  - lib/capistrano/generals/helpers.rb
@@ -76,12 +78,17 @@ files:
76
78
  - lib/capistrano/tasks/deploy/symlink.rake
77
79
  - lib/capistrano/tasks/git.rake
78
80
  - lib/capistrano/tasks/nginx.rake
79
- - lib/capistrano/tasks/setup.rake
81
+ - lib/capistrano/tasks/puma.rake
80
82
  - lib/capistrano/tasks/sidekiq.rake
83
+ - lib/capistrano/tasks/ssl.rake
81
84
  - lib/capistrano/tasks/unicorn.rake
82
85
  - lib/generators/capistrano/generals/nginx_generator.rb
86
+ - lib/generators/capistrano/generals/puma_generator.rb
87
+ - lib/generators/capistrano/generals/sidekiq_generator.rb
83
88
  - lib/generators/capistrano/generals/templates/_head.erb
84
89
  - lib/generators/capistrano/generals/templates/nginx.conf.erb
90
+ - lib/generators/capistrano/generals/templates/puma.rb.erb
91
+ - lib/generators/capistrano/generals/templates/puma_init.sh.erb
85
92
  - lib/generators/capistrano/generals/templates/sidekiq_init.sh.erb
86
93
  - lib/generators/capistrano/generals/templates/unicorn.rb.erb
87
94
  - lib/generators/capistrano/generals/templates/unicorn_init.sh.erb
@@ -1,41 +0,0 @@
1
- namespace :setup do
2
- #
3
- # namespace :symlink do
4
- #
5
- # desc 'Symlink config file for nginx'
6
- # task :nginx do
7
- # on roles :app do
8
- # # Find stage specific config file
9
- # file_name = File.join current_path, 'config/nginx.conf'
10
- # file_name = get_config_file(file_name, fetch(:stage).to_s)
11
- # execute "ln -nfs #{file_name} /etc/nginx/sites-enabled/#{fetch(:application)}_#{fetch(:stage)}"
12
- # end
13
- # end
14
- #
15
- # desc 'Symlink config file for unicorn'
16
- # task :unicorn do
17
- # on roles :app do
18
- # # Find stage specific config file
19
- # file_name = File.join current_path, 'config/unicorn_init.sh'
20
- # file_name = get_config_file(file_name, fetch(:stage).to_s)
21
- # execute "ln -nfs #{file_name} /etc/init.d/unicorn_#{fetch(:application)}_#{fetch(:stage)}"
22
- # # Start unicorn at startup
23
- # execute "sudo update-rc.d unicorn_#{fetch(:application)}_#{fetch(:stage)} defaults"
24
- # end
25
- # end
26
- #
27
- # desc 'Symlink config file for sidekiq'
28
- # task :sidekiq do
29
- # on roles :app do
30
- # # Find stage specific config file
31
- # file_name = File.join current_path, 'config/sidekiq_init.sh'
32
- # file_name = get_config_file(file_name, fetch(:stage).to_s)
33
- # execute "ln -nfs #{file_name} /etc/init.d/sidekiq_#{fetch(:application)}_#{fetch(:stage)}"
34
- # # Start unicorn at startup
35
- # execute "sudo update-rc.d sidekiq_#{fetch(:application)}_#{fetch(:stage)} defaults"
36
- # end
37
- # end
38
- #
39
- # end
40
- #
41
- end