capistrano3-nginx 2.0.3 → 2.0.4

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: da34c825fe392851478096964b1e097cbdfdfc87
4
- data.tar.gz: b7b89cab7c7bc9a51e806ed30182dceacc07f24c
3
+ metadata.gz: d6c36175c240e56d54ac11b590af9a7c6e5defc2
4
+ data.tar.gz: 37600630f2ce5e64308173efd71579756525733b
5
5
  SHA512:
6
- metadata.gz: a73e1ece05374418c0e888d6830fbcf19b07d74b1545637e54ac23273277ff7649fbbb28c1c1db72668084b8f9f3bac09cef963f59baebccc5c4e861f75f4f27
7
- data.tar.gz: e71dc20374bd4a5dd23a93542d64b9178097e0db730e6783774f07dcb4a2f83f2196474edf294dfaf19c124751b6a425b284cac8e5e450e5a2f5477e11a9ce3e
6
+ metadata.gz: 4af5c0e6330e52b6b92e37445aed121f0c22c4bcb89518928e77776381d634a8b05bc5765d96314e060b2093e2f980aa702615b5ec96ef7fe3553bdb7b1aafea
7
+ data.tar.gz: f0cd6472ba9161f2b9d4412a1d89cfa8d5b02b32530eb3a544ac5b66edde994f0d2f7f95567412254dde12169a96faa7b5fc98552f5f984230e2cff1cc3f8ed2
@@ -0,0 +1 @@
1
+ pkg/
data/README.md CHANGED
@@ -46,6 +46,17 @@ Configurable options (copy into deploy.rb), shown here with examples:
46
46
  # No default vaue
47
47
  set :nginx_domains, "foo.bar.com"
48
48
 
49
+ # Sudo usage can be enables on task and/or path level.
50
+ # If sudo is enabled for a specific task (i.e. 'nginx:site:add') every
51
+ # command in that task will be run using sudo priviliges.
52
+ # If sudo is enables for a specific path (i.e. :nginx_sites_enabled_dir)
53
+ # only command manipulating that directory will be run using sudo privileges.
54
+ # Note: When options overlap, sudo is used if either option permits it.
55
+ #
56
+ # Everything is run as sudo per default.
57
+ # set :nginx_sudo_paths, [:nginx_log_path, :nginx_sites_enabled_dir, :nginx_sites_available_dir]
58
+ # set :nginx_sudo_tasks, ['nginx:start', 'nginx:stop', 'nginx:restart', 'nginx:reload', 'nginx:configtest', 'nginx:site:add', 'nginx:site:disable', 'nginx:site:enable', 'nginx:site:remove' ]
59
+
49
60
  # nginx service script
50
61
  # Defaults to using the 'service' convinience script.
51
62
  # You might prefer using the init.d instead depending on sudo privilages.
@@ -70,11 +81,11 @@ set :nginx_static_dir, "my_static_folder"
70
81
 
71
82
  # Path where nginx available site are stored
72
83
  # default value: "sites-available"
73
- set :nginx_sites_available, "sites-available"
84
+ set :nginx_sites_available_dir, "sites-available"
74
85
 
75
86
  # Path where nginx available site are stored
76
87
  # default value: "sites-enabled"
77
- set :nginx_sites_enabled, "sites-enabled"
88
+ set :nginx_sites_enabled_dir, "sites-enabled"
78
89
 
79
90
  # Path to look for custom config template
80
91
  # `:default` will use the bundled nginx template
@@ -130,3 +141,15 @@ Thansk for the inspiration on several nginx recipes out there
130
141
  3. Commit your changes (`git commit -am 'Add some feature'`)
131
142
  4. Push to the branch (`git push origin my-new-feature`)
132
143
  5. Create new Pull Request
144
+
145
+ ## Credits
146
+
147
+ Thank you [contributors](https://github.com/platanus/guides/graphs/contributors)!
148
+
149
+ <img src="http://platan.us/gravatar_with_text.png" alt="Platanus" width="250"/>
150
+
151
+ capistrano3-nginx is maintained by [platanus](http://platan.us).
152
+
153
+ ## License
154
+
155
+ Guides is © 2014 platanus, spa. It is free software and may be redistributed under the terms specified in the LICENSE file.
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'capistrano3-nginx'
7
- spec.version = '2.0.3'
7
+ spec.version = '2.0.4'
8
8
  spec.authors = ['Juan Ignacio Donoso']
9
9
  spec.email = ['jidonoso@gmail.com']
10
10
  spec.description = %q{Adds suuport to nginx for Capistrano 3.x}
@@ -1,45 +1,90 @@
1
1
  namespace :load do
2
2
  task :defaults do
3
- set :nginx_service_path, -> { 'service nginx' }
4
- set :nginx_roles, -> { :web }
5
- set :nginx_log_path, -> { "#{shared_path}/log" }
6
- set :nginx_root_path, -> { "/etc/nginx" }
7
- set :nginx_static_dir, -> { "public" }
8
- set :nginx_sites_enabled, -> { "sites-enabled" }
9
- set :nginx_sites_available, -> { "sites-available" }
10
- set :nginx_template, -> { :default }
11
- set :nginx_use_ssl, -> { false }
12
- set :nginx_ssl_certificate, -> { "#{fetch(:application)}.crt" }
13
- set :nginx_ssl_certificate_path, -> { '/etc/ssl/certs' }
14
- set :nginx_ssl_certificate_key, -> { "#{fetch(:application)}.crt" }
3
+ set :nginx_sudo_paths, -> { [:nginx_log_path, :nginx_sites_enabled_dir, :nginx_sites_available_dir] }
4
+ set :nginx_sudo_tasks, -> { ['nginx:start', 'nginx:stop', 'nginx:restart', 'nginx:reload', 'nginx:configtest', 'nginx:site:add', 'nginx:site:disable', 'nginx:site:enable', 'nginx:site:remove' ] }
5
+ set :nginx_log_path, -> { "#{shared_path}/log" }
6
+ set :nginx_root_path, -> { "/etc/nginx" }
7
+ set :nginx_service_path, -> { 'service nginx' }
8
+ set :nginx_static_dir, -> { "public" }
9
+ set :nginx_sites_enabled_dir, -> { "sites-enabled" }
10
+ set :nginx_sites_available_dir, -> { "sites-available" }
11
+ set :nginx_roles, -> { :web }
12
+ set :nginx_template, -> { :default }
13
+ set :nginx_use_ssl, -> { false }
14
+ set :nginx_ssl_certificate, -> { "#{fetch(:application)}.crt" }
15
+ set :nginx_ssl_certificate_path, -> { '/etc/ssl/certs' }
16
+ set :nginx_ssl_certificate_key, -> { "#{fetch(:application)}.crt" }
15
17
  set :nginx_ssl_certificate_key_path, -> { '/etc/ssl/private' }
16
- set :app_server, -> { true }
18
+ set :app_server, -> { true }
17
19
  end
18
20
  end
19
21
 
20
22
  namespace :nginx do
23
+
24
+ # prepend :sudo to list if arguments if :key is in :nginx_use_sudo_for list
25
+ def add_sudo_if_required argument_list, *keys
26
+ keys.each do | key |
27
+ if use_sudo? key
28
+ argument_list.unshift(:sudo)
29
+ break
30
+ end
31
+ end
32
+ end
33
+
34
+ def use_sudo? key
35
+ return (fetch(:nginx_sudo_tasks).include?(key) || fetch(:nginx_sudo_paths).include?(key))
36
+ end
37
+
38
+ def valid_nginx_config?
39
+ test_sudo = use_sudo?('nginx:configtest') ? 'sudo ' : ''
40
+ nginx_service = fetch(:nginx_service_path)
41
+ test "[ $(#{test_sudo}#{nginx_service} configtest | grep -c 'fail') -eq 0 ]"
42
+ end
43
+
21
44
  task :load_vars do
22
- set :sites_available, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_available)) }
23
- set :sites_enabled, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_enabled)) }
24
- set :enabled_application, -> { File.join(fetch(:sites_enabled), fetch(:application)) }
45
+ set :sites_available, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_available_dir)) }
46
+ set :sites_enabled, -> { File.join(fetch(:nginx_root_path), fetch(:nginx_sites_enabled_dir)) }
47
+ set :enabled_application, -> { File.join(fetch(:sites_enabled), fetch(:application)) }
25
48
  set :available_application, -> { File.join(fetch(:sites_available), fetch(:application)) }
26
49
  end
27
50
 
51
+ # validate_sudo_settings
52
+ task :validate_user_settings do
53
+ path_and_dir_keys = [:nginx_log_path, :nginx_sites_enabled_dir, :nginx_sites_available_dir]
54
+ nginx_task_keys = ['nginx:start', 'nginx:stop', 'nginx:restart', 'nginx:reload', 'nginx:configtest', 'nginx:site:add', 'nginx:site:disable', 'nginx:site:enable', 'nginx:site:remove' ]
55
+
56
+ fetch(:nginx_sudo_paths).each do | path |
57
+ abort("Invalid value in :nginx_sudo_paths, Unknown symbol '#{path}'") unless path_and_dir_keys.include? path
58
+ end
59
+ fetch(:nginx_sudo_tasks).each do | task |
60
+ abort("Invalid symbol in :nginx_tasks! Unknown symbol '#{task}'") unless nginx_task_keys.include? task
61
+ end
62
+ end
63
+
64
+ desc "Configtest nginx service"
65
+ task :configtest do
66
+ on release_roles fetch(:nginx_roles) do
67
+ abort("nginx configuration is invalid! (Make sure nginx configuration files are readable and correctly formated.)") unless valid_nginx_config?
68
+ end
69
+ end
70
+
28
71
  %w[start stop restart reload].each do |command|
29
72
  desc "#{command.capitalize} nginx service"
30
- task command do
31
- nginx_service = fetch(:nginx_service_path)
73
+ task command => ['nginx:validate_user_settings'] do
32
74
  on release_roles fetch(:nginx_roles) do
33
- if command === 'stop' || (test "[ $(sudo #{nginx_service} configtest | grep -c 'fail') -eq 0 ]")
34
- execute :sudo, "#{nginx_service} #{command}"
35
- end
75
+ arguments = fetch(:nginx_service_path), command
76
+ add_sudo_if_required arguments, "nginx:#{command}"
77
+ execute *arguments
36
78
  end
37
79
  end
80
+ before "nginx:#{command}", 'nginx:configtest' unless command == 'stop'
38
81
  end
39
82
 
40
83
  after 'deploy:check', nil do
41
84
  on release_roles fetch(:nginx_roles) do
42
- execute :mkdir, '-pv', fetch(:nginx_log_path)
85
+ arguments = :mkdir, '-pv', fetch(:nginx_log_path)
86
+ add_sudo_if_required arguments, :nginx_log_path
87
+ execute *arguments
43
88
  end
44
89
  end
45
90
 
@@ -54,7 +99,7 @@ namespace :nginx do
54
99
 
55
100
  namespace :site do
56
101
  desc 'Creates the site configuration and upload it to the available folder'
57
- task :add => ['nginx:load_vars'] do
102
+ task :add => ['nginx:load_vars', 'nginx:validate_user_settings'] do
58
103
  on release_roles fetch(:nginx_roles) do
59
104
  within fetch(:sites_available) do
60
105
  config_file = fetch(:nginx_template)
@@ -63,40 +108,46 @@ namespace :nginx do
63
108
  end
64
109
  config = ERB.new(File.read(config_file)).result(binding)
65
110
  upload! StringIO.new(config), '/tmp/nginx.conf'
66
-
67
- execute :sudo, :mv, '/tmp/nginx.conf', fetch(:application)
111
+ arguments = :mv, '/tmp/nginx.conf', fetch(:application)
112
+ add_sudo_if_required arguments, 'nginx:sites:add', :nginx_sites_available_dir
113
+ execute *arguments
68
114
  end
69
115
  end
70
116
  end
71
117
 
72
118
  desc 'Enables the site creating a symbolic link into the enabled folder'
73
- task :enable => ['nginx:load_vars'] do
119
+ task :enable => ['nginx:load_vars', 'nginx:validate_user_settings'] do
74
120
  on release_roles fetch(:nginx_roles) do
75
121
  if test "! [ -h #{fetch(:enabled_application)} ]"
76
122
  within fetch(:sites_enabled) do
77
- execute :sudo, :ln, '-nfs', fetch(:available_application), fetch(:enabled_application)
123
+ arguments = :ln, '-nfs', fetch(:available_application), fetch(:enabled_application)
124
+ add_sudo_if_required arguments, 'nginx:sites:enable', :nginx_sites_enabled_dir
125
+ execute *arguments
78
126
  end
79
127
  end
80
128
  end
81
129
  end
82
130
 
83
131
  desc 'Disables the site removing the symbolic link located in the enabled folder'
84
- task :disable => ['nginx:load_vars'] do
132
+ task :disable => ['nginx:load_vars', 'nginx:validate_user_settings'] do
85
133
  on release_roles fetch(:nginx_roles) do
86
134
  if test "[ -f #{fetch(:enabled_application)} ]"
87
135
  within fetch(:sites_enabled) do
88
- execute :sudo, :rm, '-f', fetch(:application)
136
+ arguments = :rm, '-f', fetch(:application)
137
+ add_sudo_if_required arguments, 'nginx:sites:disable', :nginx_sites_enabled_dir
89
138
  end
90
139
  end
91
140
  end
92
141
  end
93
142
 
94
- desc 'Removes the site removing the configuration file from the available folder'
95
- task :remove => ['nginx:load_vars'] do
143
+ desc 'Removes the site by removing the configuration file from the available folder'
144
+ task :remove => ['nginx:load_vars', 'nginx:validate_user_settings'] do
96
145
  on release_roles fetch(:nginx_roles) do
97
146
  if test "[ -f #{fetch(:available_application)} ]"
98
147
  within fetch(:sites_available) do
99
- execute :sudo, :rm, fetch(:application)
148
+ arguments = :rm, fetch(:application)
149
+ add_sudo_if_required arguments, 'nginx:sites:remove', :nginx_sites_available_dir
150
+ execute *arguments
100
151
  end
101
152
  end
102
153
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano3-nginx
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.3
4
+ version: 2.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Ignacio Donoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-17 00:00:00.000000000 Z
11
+ date: 2014-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - .gitignore
48
49
  - Gemfile
49
50
  - LICENSE
50
51
  - LICENSE.txt