capistrano-unicorn-nginx 1.0.0 → 1.0.1

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: feb8b0da77445c6c9ab71b8cb47ebd81beaeeb73
4
- data.tar.gz: 67825da92ed8d2d476f6f35ad797974b494c60f0
3
+ metadata.gz: 3e038ef42790b2e2e9fdbc34f37ac6d4b44e1f4b
4
+ data.tar.gz: 7180b47e77e78edc458a79911acc901df9a95a6e
5
5
  SHA512:
6
- metadata.gz: 4f90081c4e412b9e724eadb8523a4de5a5f2b7ec4006a2c7c83ee4dceb6d0925cc2fdb23857ff944477268ebbcdbc68a7687792f6214673705b9fad0fbd6d851
7
- data.tar.gz: b6f29cc5a2d965c1ea751123037dd121a93010f70758d84b1ef59082f7986966c3d32f67e544bb524126983b29b95d823f71aee43b198ca972132ccd4c8325a3
6
+ metadata.gz: f39f6cbd00235af5642493388123b78b084499076f8ca23f00ab2b08a0279211cc0a3ade952375fda65c74ec4bb8066dc09921e0b3f2ed847d41d7dd559c659f
7
+ data.tar.gz: 89ede75ee9776a58a9f0749764b888e04baea723e0b9174a804ec0a26e8f504b1674d02ff562dc09ba21c04ebd9b25fbfa1ade6fa2b180d0ef30fab8e034daed
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
+ ### v1.0.1, 2014-03-30
2
+ - refactor all unicorn and nginx paths to separate modules
3
+ - speed up `nginx:setup_ssl` task
4
+ - small README update
1
5
  ### v1.0.0, 2014-03-39
2
6
  - @bruno- all the v1.0.0 features
data/README.md CHANGED
@@ -115,15 +115,15 @@ This file will be copied to remote server. Example value:
115
115
 
116
116
  Defaults are listed near option name in the first line.
117
117
 
118
+ - `set :unicorn_service, "unicorn_#{fetch(:application)}_#{fetch(:stage)}`<br/>
119
+ Unicorn service name is `unicorn_myapp_production` by default.
120
+
118
121
  - `set :unicorn_pid, shared_path.join("tmp/pids/unicorn.pid")`<br/>
119
122
  Path for unicorn process pid file.
120
123
 
121
124
  - `set :unicorn_config, shared_path.join("config/unicorn.rb")`<br/>
122
125
  Path for unicorn config file.
123
126
 
124
- - `set :unicorn_log, shared_path.join("log/unicorn.log")`<br/>
125
- Unicorn log path.
126
-
127
127
  - `set :unicorn_workers, 2`<br/>
128
128
  Number of unicorn workers.
129
129
 
@@ -0,0 +1,53 @@
1
+ module Capistrano
2
+ module DSL
3
+ module NginxPaths
4
+
5
+ def nginx_config_tmp_file
6
+ "#{fetch(:tmp_dir)}/#{fetch(:nginx_config_name)}"
7
+ end
8
+
9
+ def nginx_sites_available_file
10
+ "/etc/nginx/sites-available/#{fetch(:nginx_config_name)}"
11
+ end
12
+
13
+ def nginx_sites_enabled_file
14
+ "/etc/nginx/sites-enabled/#{fetch(:nginx_config_name)}"
15
+ end
16
+
17
+ def nginx_service_path
18
+ '/etc/init.d/nginx'
19
+ end
20
+
21
+ def nginx_default_pid_file
22
+ '/run/nginx.pid'
23
+ end
24
+
25
+ # ssl related files
26
+ def nginx_default_ssl_cert_file_name
27
+ "#{fetch(:nginx_server_name)}.crt"
28
+ end
29
+
30
+ def nginx_default_ssl_cert_key_file_name
31
+ "#{fetch(:nginx_server_name)}.key"
32
+ end
33
+
34
+ def nginx_ssl_cert_file
35
+ "/etc/ssl/certs/#{fetch(:nginx_ssl_cert)}"
36
+ end
37
+
38
+ def nginx_ssl_cert_key_file
39
+ "/etc/ssl/private/#{fetch(:nginx_ssl_cert_key)}"
40
+ end
41
+
42
+ # log files
43
+ def nginx_access_log_file
44
+ shared_path.join('log/nginx.access.log')
45
+ end
46
+
47
+ def nginx_error_log_file
48
+ shared_path.join('log/nginx.error.log')
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,31 @@
1
+ module Capistrano
2
+ module DSL
3
+ module UnicornPaths
4
+
5
+ def unicorn_initd_tmp_file
6
+ "#{fetch(:tmp_dir)}/#{fetch(:unicorn_service)}"
7
+ end
8
+
9
+ def unicorn_initd_file
10
+ "/etc/init.d/#{fetch(:unicorn_service)}"
11
+ end
12
+
13
+ def unicorn_default_config_file
14
+ shared_path.join('config/unicorn.rb')
15
+ end
16
+
17
+ def unicorn_default_pid_file
18
+ shared_path.join('tmp/pids/unicorn.pid')
19
+ end
20
+
21
+ def unicorn_log_file
22
+ shared_path.join('log/unicorn.stdout.log')
23
+ end
24
+
25
+ def unicorn_error_log_file
26
+ shared_path.join('log/unicorn.stderr.log')
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -1,20 +1,24 @@
1
+ require 'capistrano/dsl/nginx_paths'
1
2
  require 'capistrano/unicorn_nginx/helpers'
2
3
 
3
4
  include Capistrano::UnicornNginx::Helpers
5
+ include Capistrano::DSL::NginxPaths
4
6
 
5
7
  namespace :load do
6
8
  task :defaults do
7
9
  set :templates_path, 'config/deploy/templates'
8
10
  set :nginx_config_name, -> { "#{fetch(:application)}_#{fetch(:stage)}" }
9
- set :nginx_pid, '/run/nginx.pid'
11
+ set :nginx_pid, nginx_default_pid_file
10
12
  # set :nginx_server_name # default set in the `nginx:defaults` task
11
13
  # ssl options
12
14
  set :nginx_use_ssl, false
13
- set :nginx_ssl_cert, -> { "#{fetch(:nginx_server_name)}.crt" }
14
- set :nginx_ssl_cert_key, -> { "#{fetch(:nginx_server_name)}.key" }
15
+ set :nginx_ssl_cert, -> { nginx_default_ssl_cert_file_name }
16
+ set :nginx_ssl_cert_key, -> { nginx_default_ssl_cert_key_file_name }
15
17
  set :nginx_upload_local_cert, true
16
18
  set :nginx_ssl_cert_local_path, -> { ask(:nginx_ssl_cert_local_path, 'Local path to ssl certificate: ') }
17
19
  set :nginx_ssl_cert_key_local_path, -> { ask(:nginx_ssl_cert_key_local_path, 'Local path to ssl certificate key: ') }
20
+
21
+ set :linked_dirs, fetch(:linked_dirs, []).push('log')
18
22
  end
19
23
  end
20
24
 
@@ -29,42 +33,37 @@ namespace :nginx do
29
33
  desc 'Setup nginx configuration'
30
34
  task :setup do
31
35
  on roles :web do
32
- config_name = fetch(:nginx_config_name)
33
- next if file_exists? "/etc/nginx/sites-available/#{config_name}"
34
-
35
- execute :mkdir, '-p', shared_path.join('log')
36
- template 'nginx_conf.erb', "#{fetch(:tmp_dir)}/#{config_name}"
37
- sudo :mv, "#{fetch(:tmp_dir)}/#{config_name}", "/etc/nginx/sites-available/#{config_name}"
38
- sudo :ln, '-fs', "/etc/nginx/sites-available/#{config_name}", "/etc/nginx/sites-enabled/#{config_name}"
36
+ next if file_exists? nginx_sites_available_file
37
+ template 'nginx_conf.erb', nginx_config_tmp_file
38
+ sudo :mv, nginx_config_tmp_file, nginx_sites_available_file
39
+ sudo :ln, '-fs', nginx_sites_available_file, nginx_sites_enabled_file
39
40
  end
40
41
  end
41
42
 
42
43
  desc 'Setup nginx ssl certs'
43
44
  task :setup_ssl do
45
+ next unless fetch(:nginx_use_ssl)
44
46
  on roles :web do
45
- next unless fetch(:nginx_use_ssl)
46
- next if file_exists?("/etc/ssl/certs/#{fetch(:nginx_ssl_cert)}") && file_exists?("/etc/ssl/private/#{fetch(:nginx_ssl_cert_key)}")
47
-
47
+ next if file_exists?(nginx_ssl_cert_file) && file_exists?(nginx_ssl_cert_key_file)
48
48
  if fetch(:nginx_upload_local_cert)
49
- upload! fetch(:nginx_ssl_cert_local_path), "#{fetch(:tmp_dir)}/#{fetch(:nginx_ssl_cert)}"
50
- upload! fetch(:nginx_ssl_cert_key_local_path), "#{fetch(:tmp_dir)}/#{fetch(:nginx_ssl_cert_key)}"
51
- sudo :mv, "#{fetch(:tmp_dir)}/#{fetch(:nginx_ssl_cert)}", "/etc/ssl/certs/#{fetch(:nginx_ssl_cert)}"
52
- sudo :mv, "#{fetch(:tmp_dir)}/#{fetch(:nginx_ssl_cert_key)}", "/etc/ssl/private/#{fetch(:nginx_ssl_cert_key)}"
49
+ upload! fetch(:nginx_ssl_cert_local_path), nginx_ssl_cert_file
50
+ upload! fetch(:nginx_ssl_cert_key_local_path), nginx_ssl_cert_key_file
53
51
  end
54
- sudo :chown, 'root:root', "/etc/ssl/certs/#{fetch(:nginx_ssl_cert)}"
55
- sudo :chown, 'root:root', "/etc/ssl/private/#{fetch(:nginx_ssl_cert_key)}"
52
+ sudo :chown, 'root:root', nginx_ssl_cert_file
53
+ sudo :chown, 'root:root', nginx_ssl_cert_key_file
56
54
  end
57
55
  end
58
56
 
59
57
  desc 'Reload nginx configuration'
60
58
  task :reload do
61
59
  on roles :web do
62
- sudo '/etc/init.d/nginx reload'
60
+ sudo nginx_service_path, 'reload'
63
61
  end
64
62
  end
65
63
 
66
64
  before :setup, :defaults
67
65
  before :setup_ssl, :defaults
66
+
68
67
  end
69
68
 
70
69
  namespace :deploy do
@@ -1,34 +1,38 @@
1
+ require 'capistrano/dsl/unicorn_paths'
1
2
  require 'capistrano/unicorn_nginx/helpers'
2
3
 
3
4
  include Capistrano::UnicornNginx::Helpers
5
+ include Capistrano::DSL::UnicornPaths
4
6
 
5
7
  namespace :load do
6
8
  task :defaults do
7
- set :unicorn_service_name, -> { "unicorn_#{fetch(:application)}_#{fetch(:stage)}" }
8
- set :templates_path, "config/deploy/templates"
9
- set :unicorn_pid, -> { shared_path.join("tmp/pids/unicorn.pid") }
10
- set :unicorn_config, -> { shared_path.join("config/unicorn.rb") }
11
- set :unicorn_log, -> { shared_path.join("log/unicorn.log") }
12
- set :unicorn_user, nil # user is set by executing `id -un` on the server
9
+ set :unicorn_service, -> { "unicorn_#{fetch(:application)}_#{fetch(:stage)}" }
10
+ set :templates_path, 'config/deploy/templates'
11
+ set :unicorn_pid, -> { unicorn_default_pid_file }
12
+ set :unicorn_config, -> { unicorn_default_config_file }
13
13
  set :unicorn_workers, 2
14
+ # set :unicorn_user # default set in `unicorn:defaults` task
14
15
 
15
16
  set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids')
16
17
  end
17
18
  end
18
19
 
19
20
  namespace :unicorn do
21
+
22
+ task :defaults do
23
+ on roles :app do
24
+ set :unicorn_user, fetch(:unicorn_user, deploy_user)
25
+ end
26
+ end
27
+
20
28
  desc 'Setup Unicorn initializer'
21
29
  task :setup_initializer do
22
30
  on roles :app do
23
- next if file_exists? "/etc/init.d/#{fetch(:unicorn_service_name)}"
24
-
25
- set :unicorn_user, capture(:id, '-un') unless fetch(:unicorn_user)
26
- init_tmp = "#{fetch(:tmp_dir)}/unicorn_init"
27
-
28
- template 'unicorn_init.erb', init_tmp
29
- execute :chmod, "+x", init_tmp
30
- sudo :mv, init_tmp, "/etc/init.d/#{fetch(:unicorn_service_name)}"
31
- sudo 'update-rc.d', '-f', fetch(:unicorn_service_name), 'defaults'
31
+ next if file_exists? unicorn_initd_file
32
+ template 'unicorn_init.erb', unicorn_initd_tmp_file
33
+ execute :chmod, '+x', unicorn_initd_tmp_file
34
+ sudo :mv, unicorn_initd_tmp_file, unicorn_initd_file
35
+ sudo 'update-rc.d', '-f', fetch(:unicorn_service), 'defaults'
32
36
  end
33
37
  end
34
38
 
@@ -36,10 +40,6 @@ namespace :unicorn do
36
40
  task :setup_app_config do
37
41
  on roles :app do
38
42
  next if file_exists? fetch(:unicorn_config)
39
-
40
- execute :mkdir, '-p', shared_path.join('config')
41
- execute :mkdir, '-p', shared_path.join('log')
42
- execute :mkdir, '-p', shared_path.join('tmp/pids')
43
43
  template 'unicorn.rb.erb', fetch(:unicorn_config)
44
44
  end
45
45
  end
@@ -48,10 +48,13 @@ namespace :unicorn do
48
48
  desc "#{command} unicorn"
49
49
  task command do
50
50
  on roles :app do
51
- execute :service, fetch(:unicorn_service_name), command
51
+ execute :service, fetch(:unicorn_service), command
52
52
  end
53
53
  end
54
54
  end
55
+
56
+ before :setup_initializer, :defaults
57
+
55
58
  end
56
59
 
57
60
  namespace :deploy do
@@ -22,6 +22,10 @@ module Capistrano
22
22
  test "[ -e #{path} ]"
23
23
  end
24
24
 
25
+ def deploy_user
26
+ capture :id, '-un'
27
+ end
28
+
25
29
  end
26
30
  end
27
31
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module UnicornNginx
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
@@ -1,2 +1,3 @@
1
+ require 'capistrano/dsl/nginx_paths'
1
2
  load File.expand_path("../tasks/nginx.rake", __FILE__)
2
3
  load File.expand_path("../tasks/unicorn.rake", __FILE__)
@@ -13,8 +13,8 @@ server {
13
13
  <% if fetch(:nginx_use_ssl) %>
14
14
  listen 443;
15
15
  ssl on;
16
- ssl_certificate /etc/ssl/certs/<%= fetch(:nginx_ssl_certificate) %>;
17
- ssl_certificate_key /etc/ssl/private/<%= fetch(:nginx_ssl_certificate_key) %>;
16
+ ssl_certificate <%= nginx_ssl_cert_file %>;
17
+ ssl_certificate_key <%= nginx_ssl_cert_key_file %>;
18
18
  <% else %>
19
19
  listen 80;
20
20
  <% end %>
@@ -38,8 +38,8 @@ server {
38
38
  <% end %>
39
39
  proxy_pass http://unicorn_<%= fetch(:nginx_config_name) %>;
40
40
  # limit_req zone=one;
41
- access_log <%= shared_path %>/log/nginx.access.log;
42
- error_log <%= shared_path %>/log/nginx.error.log;
41
+ access_log <%= nginx_access_log_file %>;
42
+ error_log <%= nginx_error_log_file %>;
43
43
  }
44
44
 
45
45
  location ^~ /assets/ {
@@ -1,7 +1,7 @@
1
1
  working_directory "<%= current_path %>"
2
2
  pid "<%= fetch(:unicorn_pid) %>"
3
- stderr_path "<%= fetch(:unicorn_log) %>"
4
- stdout_path "<%= fetch(:unicorn_log) %>"
3
+ stdout_path "<%= unicorn_log_file %>"
4
+ stderr_path "<%= unicorn_error_log_file %>"
5
5
 
6
6
  listen "/tmp/unicorn.<%= fetch(:nginx_config_name) %>.sock"
7
7
  worker_processes <%= fetch(:unicorn_workers) %>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-unicorn-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Sutic
@@ -72,6 +72,8 @@ files:
72
72
  - Rakefile
73
73
  - capistrano-unicorn-nginx.gemspec
74
74
  - lib/capistrano-unicorn-nginx.rb
75
+ - lib/capistrano/dsl/nginx_paths.rb
76
+ - lib/capistrano/dsl/unicorn_paths.rb
75
77
  - lib/capistrano/tasks/nginx.rake
76
78
  - lib/capistrano/tasks/unicorn.rake
77
79
  - lib/capistrano/unicorn_nginx.rb