capistrano-exfel 0.0.14 → 0.0.16

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: '0569ba176090d8b657cc3b7059eb8082da43c73f'
4
- data.tar.gz: 9a2bb7195b604db0fc96609349e843ad0a1866dd
3
+ metadata.gz: 2d5b83d102f385412f3033766066c168e36c0664
4
+ data.tar.gz: dee59900cbfcefe28b4daf36524972b0ff3a356b
5
5
  SHA512:
6
- metadata.gz: 76fdc51fbf356b166ba49139246e8ee75b12c87f00d1002dd417e570801553ad34b19f570418c0c0b4d4f7b6cdf2a55ce79a35054a7fe13d5c38c10c6a98d21c
7
- data.tar.gz: d7c38561029507cc3c4167ff7069a19715ceda2afea9b6de631c6e307333c8721e2f0bdd9348c516fa7fa598d4acd63d24d512c663d24faacf17709d1cd57b74
6
+ metadata.gz: a433e4230b37e00f681ebf6999bf8435a0de194ab0ea6f0916782d95ea30f8d450e81e0cb98ae3a56d3567b71ff9f762d97d3cf27465fc48808b5653d427ac9e
7
+ data.tar.gz: 214ac7f19d5ad2457930a501282abefb66e5a502a5198eab2cc5818ae9b44e72320e2e4857d6e1e2397c051a6eaf727a6c1ed9188cee2b95032520d571923e15
data/.rubocop.yml CHANGED
@@ -22,4 +22,10 @@ Style/Lambda:
22
22
  #
23
23
  # Block has too many lines.
24
24
  Metrics/BlockLength:
25
- Max: 100 # Default 25
25
+ Max: 160 # Default 25
26
+
27
+ #
28
+ # Use 2 spaces for indentation in a heredoc by using some library(e.g. ActiveSupport's String#strip_heredoc).
29
+ Style/IndentHeredoc:
30
+ Exclude:
31
+ - 'lib/capistrano/tasks/apache_sl6.rake'
data/Gemfile CHANGED
@@ -4,4 +4,4 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  # Use Rubocop to validate ruby code syntax
7
- gem 'rubocop', '~> 0.47.1', require: false, group: :development
7
+ gem 'rubocop', '0.48.0', require: false, group: :development
data/README.md CHANGED
@@ -12,7 +12,7 @@ Add these lines to your application's Gemfile:
12
12
  gem 'capistrano', '~> 3.4.0'
13
13
  gem 'capistrano-rails', '~> 1.1.2'
14
14
  gem 'capistrano-rvm', '~> 0.1.2'
15
- gem 'capistrano-exfel', '~> 0.0.14'
15
+ gem 'capistrano-exfel', '~> 0.0.16'
16
16
 
17
17
  And then execute:
18
18
 
@@ -24,11 +24,17 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
- Add this line to your `Capfile`:
27
+ Add this line to your `Capfile` for Scientific Linux 6 machines:
28
28
 
29
29
  # Load Capistrano Exfel Scientific Linux 6 tasks
30
30
  require 'capistrano/exfel/sl6'
31
31
 
32
+ Add this line to your `Capfile` for CentOS 7 machines::
33
+
34
+ # Load Capistrano Exfel CentOS tasks
35
+ require 'capistrano/exfel/co7'
36
+
37
+
32
38
  This gem will reuse `capistrano-rails` and `capistrano-rvm` tasks to build the following tasks:
33
39
 
34
40
  Task **application:deploy_first_time**:
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'capistrano/exfel/version'
@@ -0,0 +1,20 @@
1
+ # Load DSL and Setup Up Stages
2
+ require 'capistrano/setup'
3
+
4
+ # Includes default deployment tasks
5
+ require 'capistrano/deploy'
6
+
7
+ # Includes tasks from other gems included in your Gemfile
8
+ require 'capistrano/rvm'
9
+
10
+ # We're going to use the full capistrano/rails since
11
+ # it includes the asset compilation, DB migrations and bundler
12
+ require 'capistrano/rails'
13
+
14
+ load File.expand_path('../../tasks/apache.rake', __FILE__)
15
+ load File.expand_path('../../tasks/apache_co7.rake', __FILE__)
16
+ load File.expand_path('../../tasks/app_home.rake', __FILE__)
17
+ load File.expand_path('../../tasks/application.rake', __FILE__)
18
+ load File.expand_path('../../tasks/database.rake', __FILE__)
19
+ load File.expand_path('../../tasks/secrets.rake', __FILE__)
20
+ load File.expand_path('../../tasks/util.rake', __FILE__)
@@ -12,6 +12,7 @@ require 'capistrano/rvm'
12
12
  require 'capistrano/rails'
13
13
 
14
14
  load File.expand_path('../../tasks/apache.rake', __FILE__)
15
+ load File.expand_path('../../tasks/apache_sl6.rake', __FILE__)
15
16
  load File.expand_path('../../tasks/app_home.rake', __FILE__)
16
17
  load File.expand_path('../../tasks/application.rake', __FILE__)
17
18
  load File.expand_path('../../tasks/database.rake', __FILE__)
@@ -1,6 +1,6 @@
1
1
  module Capistrano
2
2
  # Capistrano::Exfel version information
3
3
  module Exfel
4
- VERSION = '0.0.14'.freeze
4
+ VERSION = '0.0.16'.freeze
5
5
  end
6
6
  end
@@ -0,0 +1,6 @@
1
+ LoadModule passenger_module <<PASSENGER_ROOT>>/buildout/apache2/mod_passenger.so
2
+ <IfModule mod_passenger.c>
3
+ PassengerRoot <<PASSENGER_ROOT>>
4
+ PassengerDefaultRuby <<RUBY_PATH>>
5
+ </IfModule>
6
+
@@ -0,0 +1,7 @@
1
+ ##################################################
2
+ # Redirect all HTTP requests to HTTPS
3
+ ##################################################
4
+ <VirtualHost *:80>
5
+ ServerName <<SERVER_NAME>>
6
+ Redirect / <<APP_DOMAIN>>
7
+ </VirtualHost>
@@ -0,0 +1,71 @@
1
+ Listen 443 https
2
+
3
+ SSLPassPhraseDialog exec:/usr/libexec/httpd-ssl-pass-dialog
4
+
5
+ SSLSessionCache shmcb:/run/httpd/sslcache(512000)
6
+ SSLSessionCacheTimeout 300
7
+
8
+ SSLRandomSeed startup file:/dev/urandom 256
9
+ SSLRandomSeed connect builtin
10
+
11
+ SSLCryptoDevice builtin
12
+
13
+ <VirtualHost _default_:443>
14
+
15
+ ErrorLog logs/ssl_error_log
16
+ TransferLog logs/ssl_access_log
17
+ LogLevel warn
18
+
19
+ SSLEngine on
20
+
21
+ SSLProtocol all -SSLv2
22
+
23
+ SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5:!SEED:!IDEA
24
+
25
+ SSLCertificateFile /etc/pki/tls/certs/localhost.crt
26
+
27
+ SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
28
+
29
+ <Files ~ "\.(cgi|shtml|phtml|php3?)$">
30
+ SSLOptions +StdEnvVars
31
+ </Files>
32
+ <Directory "/var/www/cgi-bin">
33
+ SSLOptions +StdEnvVars
34
+ </Directory>
35
+
36
+ BrowserMatch "MSIE [2-5]" \
37
+ nokeepalive ssl-unclean-shutdown \
38
+ downgrade-1.0 force-response-1.0
39
+
40
+ CustomLog logs/ssl_request_log \
41
+ "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
42
+ # <<APPLICATION_NAME>> - Ruby on Rails Application
43
+ #
44
+ # Application secured by SSL
45
+
46
+ Alias /<<APPLICATION_NAME>> /var/www/html/<<APPLICATION_NAME>>
47
+
48
+ #
49
+ # Passenger
50
+ #
51
+ PassengerResolveSymlinksInDocumentRoot on
52
+
53
+ #
54
+ # Application
55
+ #
56
+ <Directory "/var/www/html/<<APPLICATION_NAME>>/">
57
+ RackBaseURI /<<APPLICATION_NAME>>
58
+ RailsEnv <<ENVIRONMENT>>
59
+
60
+ PassengerUser nobody
61
+ # Scientific Linux: nobody / Ubuntu/Debian: nogroup
62
+ PassengerGroup nobody
63
+
64
+ # This relaxes Apache security settings.
65
+ Options -Indexes +MultiViews +FollowSymLinks
66
+ AllowOverride None
67
+ Require all granted
68
+ </Directory>
69
+
70
+ </VirtualHost>
71
+
@@ -0,0 +1,68 @@
1
+
2
+ ServerRoot "/etc/httpd"
3
+ Listen 80
4
+
5
+ Include conf.modules.d/*.conf
6
+
7
+ User apache
8
+ Group apache
9
+
10
+ ServerAdmin root@localhost
11
+ ServerSignature Off
12
+ ServerTokens Prod
13
+
14
+ <Directory />
15
+ AllowOverride none
16
+ Require all denied
17
+ </Directory>
18
+
19
+ DocumentRoot "/var/www/html"
20
+
21
+ <Directory "/var/www">
22
+ AllowOverride None
23
+ Require all granted
24
+ </Directory>
25
+
26
+ <Directory "/var/www/html">
27
+ Options Indexes FollowSymLinks
28
+ AllowOverride None
29
+ Require all granted
30
+ </Directory>
31
+
32
+ <IfModule dir_module>
33
+ DirectoryIndex index.html
34
+ </IfModule>
35
+
36
+ <Files ".ht*">
37
+ Require all denied
38
+ </Files>
39
+
40
+ ErrorLog "logs/error_log"
41
+
42
+ LogLevel warn
43
+
44
+ <IfModule log_config_module>
45
+ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
46
+ LogFormat "%h %l %u %t \"%r\" %>s %b" common
47
+ <IfModule logio_module>
48
+ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
49
+ </IfModule>
50
+ CustomLog "logs/access_log" combined
51
+ </IfModule>
52
+
53
+
54
+ <IfModule mime_module>
55
+ TypesConfig /etc/mime.types
56
+ AddType application/x-compress .Z
57
+ AddType application/x-gzip .gz .tgz
58
+ </IfModule>
59
+
60
+ AddDefaultCharset UTF-8
61
+
62
+ <IfModule mime_magic_module>
63
+ MIMEMagicFile conf/magic
64
+ </IfModule>
65
+
66
+
67
+ EnableSendfile on
68
+ IncludeOptional conf.d/*.conf
@@ -47,24 +47,6 @@ namespace :apache do
47
47
  end
48
48
  end
49
49
 
50
- desc 'Configure Apache configuration files'
51
- task :configure do
52
- on roles(:app) do
53
- sudo_cmd = "echo #{fetch(:password)} | sudo -S"
54
-
55
- set :shared_path, "#{fetch(:deploy_to)}/shared"
56
- set :shared_apache_path, "#{fetch(:shared_path)}/apache"
57
-
58
- invoke 'apache:create_apache_shared_folder'
59
- invoke 'apache:configure_app_conf_file'
60
- invoke 'apache:configure_app_ssl_conf_file'
61
-
62
- if remote_file_exists?('/etc/httpd/conf.d/ssl.conf')
63
- execute "#{sudo_cmd} mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf_bck"
64
- end
65
- end
66
- end
67
-
68
50
  # desc 'Create Apache configuration files shared folder'
69
51
  task :create_apache_shared_folder do
70
52
  on roles(:app) do
@@ -83,66 +65,6 @@ namespace :apache do
83
65
  end
84
66
  end
85
67
 
86
- # desc 'Configure (HTTP) Apache Application configuration files'
87
- task :configure_app_conf_file do
88
- on roles(:app) do
89
- sudo_cmd = "echo #{fetch(:password)} | sudo -S"
90
-
91
- debug '#' * 50
92
- debug 'Configure (HTTP) Apache Application configuration files'
93
-
94
- set :shared_apache_conf_file, "#{fetch(:shared_apache_path)}/app_#{fetch(:app_name_uri)}.conf"
95
- http_file = File.expand_path('../../recipes/apache_http.conf', __FILE__)
96
- upload! StringIO.new(File.read(http_file)), fetch(:shared_apache_conf_file).to_s
97
-
98
- debug "chmod g+w #{fetch(:shared_apache_conf_file)}"
99
- execute "chmod g+w #{fetch(:shared_apache_conf_file)}"
100
-
101
- passenger_root = get_command_output('/usr/local/rvm/bin/rvm default do passenger-config --root')
102
- ruby_path = "/#{passenger_root.split('/')[1..5].join('/')}/wrappers/ruby"
103
- app_domain = fetch(:app_domain)
104
- server_name = app_domain.split('/')[2]
105
-
106
- debug "sed -i 's|<<PASSENGER_ROOT>>|#{passenger_root}|g' #{fetch(:shared_apache_conf_file)}"
107
- execute "sed -i 's|<<PASSENGER_ROOT>>|#{passenger_root}|g' #{fetch(:shared_apache_conf_file)}"
108
-
109
- execute "sed -i 's|<<RUBY_PATH>>|#{ruby_path}|g' #{fetch(:shared_apache_conf_file)}"
110
- execute "sed -i 's|<<APP_DOMAIN>>|#{app_domain}|g' #{fetch(:shared_apache_conf_file)}"
111
- execute "sed -i 's|<<SERVER_NAME>>|#{server_name}|g' #{fetch(:shared_apache_conf_file)}"
112
-
113
- execute "#{sudo_cmd} ln -sfn #{fetch(:shared_apache_conf_file)} /etc/httpd/conf.d/"
114
-
115
- debug '#' * 50
116
- end
117
- end
118
-
119
- # desc 'Configure (HTTPS) Apache Application configuration files'
120
- task :configure_app_ssl_conf_file do
121
- on roles(:app) do
122
- sudo_cmd = "echo #{fetch(:password)} | sudo -S"
123
-
124
- debug '#' * 50
125
- debug 'Configure (HTTPS) Apache Application configuration files'
126
-
127
- set :shared_apache_conf_ssl_file, "#{fetch(:shared_apache_path)}/app_#{fetch(:app_name_uri)}_ssl.conf"
128
- http_ssl_file = File.expand_path('../../recipes/apache_ssl.conf', __FILE__)
129
- upload! StringIO.new(File.read(http_ssl_file)), fetch(:shared_apache_conf_ssl_file).to_s
130
-
131
- debug "chmod g+w #{fetch(:shared_apache_conf_ssl_file)}"
132
- execute "chmod g+w #{fetch(:shared_apache_conf_ssl_file)}"
133
-
134
- server_name = string_between_markers(fetch(:app_domain), '://', '/')
135
-
136
- execute "sed -i 's/<<SERVER_NAME>>/#{server_name}/g' #{fetch(:shared_apache_conf_ssl_file)}"
137
- execute "sed -i 's/<<APPLICATION_NAME>>/#{fetch(:app_name_uri)}/g' #{fetch(:shared_apache_conf_ssl_file)}"
138
- execute "sed -i 's/<<ENVIRONMENT>>/#{fetch(:environment)}/g' #{fetch(:shared_apache_conf_ssl_file)}"
139
-
140
- execute "#{sudo_cmd} ln -sfn #{fetch(:shared_apache_conf_ssl_file)} /etc/httpd/conf.d/"
141
-
142
- debug '#' * 50
143
- end
144
- end
145
-
146
68
  desc 'Configure Apache to start at bootup'
147
69
  task :chkconfig_on do
148
70
  on roles(:web) do
@@ -193,169 +115,4 @@ namespace :apache do
193
115
  info '#' * 50
194
116
  end
195
117
  end
196
-
197
- desc 'Update httpd.conf to secure apache server'
198
- task :secure_apache do
199
- on roles(:web) do
200
- sudo_cmd = "echo #{fetch(:password)} | sudo -S"
201
-
202
- debug '#' * 50
203
- debug 'Update httpd.conf to secure apache server'
204
-
205
- set :httpd_conf_file, '/etc/httpd/conf/httpd.conf'
206
-
207
- # Replace the original Apache configuration file
208
- if remote_file_exists?('/etc/httpd/conf/httpd.conf_bck')
209
- info 'Apache original configuration file already backed up at: /etc/httpd/conf/httpd.conf_bck'
210
- else
211
- execute "#{sudo_cmd} cp -f #{fetch(:httpd_conf_file)} /etc/httpd/conf/httpd.conf_bck"
212
- info 'Apache original configuration file backed up at: /etc/httpd/conf/httpd.conf_bck'
213
- end
214
-
215
- # The ServerSignature directive allows the configuration of a trailing footer line under server-generated docs
216
- # Options: On | Off | EMail
217
- # More details: http://httpd.apache.org/docs/current/mod/core.html#serversignature
218
- set :server_signature_off, get_num_occurrences_in_file(fetch(:httpd_conf_file), 'ServerSignature Off')
219
-
220
- if fetch(:server_signature_off) == 1
221
- info 'ServerSignature Off is already set'
222
-
223
- else
224
- set :num_replacements, 0
225
- %w(On Off EMail).each do |option|
226
- set :server_signature_option,
227
- get_num_occurrences_in_file(fetch(:httpd_conf_file), "ServerSignature #{option}")
228
-
229
- if fetch(:server_signature_option) == 1
230
- info "sed -i 's/ServerSignature #{option}/ServerSignature Off/g' #{fetch(:httpd_conf_file)}"
231
- execute "#{sudo_cmd} sed -i 's/ServerSignature #{option}/ServerSignature Off/g' #{fetch(:httpd_conf_file)}"
232
- set :num_replacements, fetch(:num_replacements) + 1
233
- end
234
- end
235
-
236
- error 'ServerSignature was not found' if fetch(:num_replacements).zero?
237
- end
238
-
239
- # Don't give away too much information about all the subcomponents we are running.
240
- #
241
- # Options: Major|Minor|Min[imal]|Prod[uctOnly]|OS|Full
242
- # More details: http://httpd.apache.org/docs/current/mod/core.html#servertokens
243
- set :server_token_prod, get_num_occurrences_in_file(fetch(:httpd_conf_file), 'ServerTokens Prod')
244
- if fetch(:server_token_prod) == 1
245
- info 'ServerTokens Prod is already set'
246
- else
247
- set :num_replacements, 0
248
- %w(Major Minor Minimal Min ProductOnly Prod OS Full).each do |option|
249
- set :server_token_option, get_num_occurrences_in_file(fetch(:httpd_conf_file), "ServerTokens #{option}")
250
-
251
- next unless fetch(:server_token_option) == 1
252
-
253
- # Then, only if fetch(:server_token_option) == 1
254
- info "sed -i 's/ServerTokens #{option}/ServerTokens Prod/g' #{fetch(:httpd_conf_file)}"
255
- execute "#{sudo_cmd} sed -i 's/ServerTokens #{option}/ServerTokens Prod/g' #{fetch(:httpd_conf_file)}"
256
- set :num_replacements, fetch(:num_replacements) + 1
257
- end
258
-
259
- error 'ServerTokens was not found' if fetch(:num_replacements).zero?
260
- end
261
-
262
- # Do not allow browsing outside the document root
263
- #
264
- # <Directory />
265
- # Order Deny,Allow
266
- # Deny from all
267
- # Options None
268
- # AllowOverride None
269
- # </Directory>
270
- #
271
- message_line1 = '# Default Directory configuration changed via Capistrano.'
272
-
273
- set :server_dir_secure_configuration, get_num_occurrences_in_file(fetch(:httpd_conf_file), message_line1)
274
-
275
- if fetch(:server_token_prod) == 1
276
- info 'The correct directory configuration is already correctly set'
277
- else
278
-
279
- set :tmp_dir_original_config, '/tmp/tmp_dir_original_config.conf'
280
- set :tmp_dir_original_commented_config, '/tmp/tmp_dir_original_commented_config.conf'
281
- set :tmp_dir_new_config, '/tmp/tmp_dir_new_config.conf'
282
-
283
- # Create a temporary copy of the Apache configuration file
284
- set :tmp_httpd_file, '/tmp/httpd.conf'
285
- execute :cp, '-f', "#{fetch(:httpd_conf_file)} #{fetch(:tmp_httpd_file)}"
286
-
287
- set :grep_for_directory, "grep -Pzo '^([ ]*<Directory />[ ]*)(\\n.*)+(\\n[ ]*</Directory>[ ]*)(\\n){1}$' "\
288
- "#{fetch(:tmp_httpd_file)}"
289
-
290
- # How many lines have the original configuration
291
- command = "#{fetch(:grep_for_directory)} | grep -n '</Directory>' | head -n 1 | cut -d ':' -f1"
292
- set :def_directory_num_lines, get_command_output(command).to_i
293
- debug "Original configuration has #{fetch(:def_directory_num_lines)} lines."
294
-
295
- # Saves to a file the original configuration
296
- command = "#{fetch(:grep_for_directory)} | "\
297
- "head -n #{fetch(:def_directory_num_lines)} > #{fetch(:tmp_dir_original_config)}"
298
- debug command
299
- execute command
300
-
301
- # Saves to a file the original configuration commented
302
- execute :cp, '-f', "#{fetch(:tmp_dir_original_config)} #{fetch(:tmp_dir_original_commented_config)}"
303
- execute "sed -e 's/^/#/' -i #{fetch(:tmp_dir_original_commented_config)}"
304
-
305
- # Save to a file the new desired configuration
306
- new_directory_configs = <<-EOF
307
-
308
- #Do not allow browsing outside the document root
309
- <Directory />
310
- Order Deny,Allow
311
- Deny from all
312
- Options None
313
- AllowOverride None
314
- </Directory>
315
-
316
- EOF
317
- upload! StringIO.new(new_directory_configs), fetch(:tmp_dir_new_config).to_s
318
-
319
- # Update the new configuration file to have the original configuration commented
320
- debug "cat #{fetch(:tmp_dir_new_config)} >> #{fetch(:tmp_dir_original_commented_config)}"
321
- execute "cat #{fetch(:tmp_dir_new_config)} >> #{fetch(:tmp_dir_original_commented_config)}"
322
- execute "mv -f #{fetch(:tmp_dir_original_commented_config)} #{fetch(:tmp_dir_new_config)}"
323
-
324
- # Generates the special SED parameter: 'N;' per line that should be replaced
325
- special_sed_param = 'N;' * fetch(:def_directory_num_lines)
326
- debug "Special sed parameter is: ''#{special_sed_param}''"
327
-
328
- # Replace the old original directory configuration for a specific message (in the temporary file)
329
- message_complete = "#{message_line1}\\n#\\n"
330
- command_to_replace = "out=$(sed -e :a -e '$!N;s/\\n/.*/;ta' #{fetch(:tmp_dir_original_config)} | "\
331
- "sed -e :a -e '$!N;s/\//./;ta'); sed -i '/<Directory .>.*/ {#{special_sed_param} "\
332
- "s/'$out'/#{message_complete}/g}' #{fetch(:tmp_httpd_file)}"
333
- debug command_to_replace
334
- execute command_to_replace
335
-
336
- # Search for the line where the message was inserted
337
- command = "grep -n '#{message_line1}' #{fetch(:tmp_httpd_file)} | cut -d':' -f 1"
338
- debug command
339
- line_with_match = get_command_output(command).to_i
340
- next_line = line_with_match + 1
341
- debug "New configuration will be added to line #{next_line}"
342
-
343
- # Inserts the new directory configuration (with the old configuration commented)
344
- # in the line following the comment added before
345
- command = "sed '#{next_line}r #{fetch(:tmp_dir_new_config)}' < #{fetch(:tmp_httpd_file)} "\
346
- '> tmp_httpd_new_conf_merge.conf'
347
-
348
- debug command
349
- execute command
350
- execute "mv -f tmp_httpd_new_conf_merge.conf #{fetch(:tmp_httpd_file)}"
351
-
352
- # Replace the original Apache configuration file
353
- execute "#{sudo_cmd} mv -f #{fetch(:tmp_httpd_file)} #{fetch(:httpd_conf_file)}"
354
-
355
- # Remove all created temporary files
356
- execute "rm -f #{fetch(:tmp_dir_original_config)} #{fetch(:tmp_dir_original_commented_config)} "\
357
- "#{fetch(:tmp_dir_new_config)} #{fetch(:tmp_httpd_file)}"
358
- end
359
- end
360
- end
361
118
  end
@@ -0,0 +1,136 @@
1
+ namespace :apache do
2
+ desc 'Configure Apache configuration files'
3
+ task :configure do
4
+ on roles(:app) do
5
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
6
+
7
+ set :shared_path, "#{fetch(:deploy_to)}/shared"
8
+ set :shared_apache_path, "#{fetch(:shared_path)}/apache"
9
+
10
+ invoke 'apache:create_apache_shared_folder'
11
+ invoke 'apache:configure_apache_modules'
12
+ invoke 'apache:configure_app_conf_file'
13
+ invoke 'apache:configure_app_ssl_conf_file'
14
+
15
+ if remote_file_exists?('/etc/httpd/conf.d/ssl.conf')
16
+ execute "#{sudo_cmd} mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf_bck"
17
+ end
18
+ end
19
+ end
20
+
21
+ desc 'Configure (HTTP) Apache modules'
22
+ task :configure_apache_modules do
23
+ on roles(:app) do
24
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
25
+
26
+ debug '#' * 50
27
+ debug 'Configure (HTTP) Apache Passenger module'
28
+
29
+ set :shared_passenger_file, "#{fetch(:shared_apache_path)}/00-passenger.conf"
30
+ passenger_file = File.expand_path('../../recipes/co7/00-passenger.conf', __FILE__)
31
+
32
+ upload! StringIO.new(File.read(passenger_file)), fetch(:shared_passenger_file).to_s
33
+
34
+ debug "chmod g+w #{fetch(:shared_passenger_file)}"
35
+ execute "chmod g+w #{fetch(:shared_passenger_file)}"
36
+
37
+ passenger_root = get_command_output('/usr/local/rvm/bin/rvm default do passenger-config --root')
38
+ ruby_path = "/#{passenger_root.split('/')[1..5].join('/')}/wrappers/ruby"
39
+
40
+ debug "sed -i 's|<<PASSENGER_ROOT>>|#{passenger_root}|g' #{fetch(:shared_passenger_file)}"
41
+ execute "sed -i 's|<<PASSENGER_ROOT>>|#{passenger_root}|g' #{fetch(:shared_passenger_file)}"
42
+ execute "sed -i 's|<<RUBY_PATH>>|#{ruby_path}|g' #{fetch(:shared_passenger_file)}"
43
+
44
+ execute "#{sudo_cmd} ln -sfn #{fetch(:shared_passenger_file)} /etc/httpd/conf.modules.d/"
45
+
46
+ debug '#' * 50
47
+ debug 'Deactivate unnecessary Apache modules'
48
+ %w(00-dav.conf 00-lua.conf 00-proxy.conf 01-cgi.conf).each do |file|
49
+ if remote_file_exists?("/etc/httpd/conf.modules.d/#{file}")
50
+ execute "#{sudo_cmd} mv /etc/httpd/conf.modules.d/#{file} /etc/httpd/conf.modules.d/#{file}_bck"
51
+ end
52
+ end
53
+ debug '#' * 50
54
+ end
55
+ end
56
+
57
+ # desc 'Configure (HTTP) Apache Application configuration files'
58
+ task :configure_app_conf_file do
59
+ on roles(:app) do
60
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
61
+
62
+ debug '#' * 50
63
+ debug 'Configure (HTTP) Apache Application configuration files'
64
+
65
+ set :shared_apache_conf_file, "#{fetch(:shared_apache_path)}/app_#{fetch(:app_name_uri)}.conf"
66
+ http_file = File.expand_path('../../recipes/co7/apache_http.conf', __FILE__)
67
+ upload! StringIO.new(File.read(http_file)), fetch(:shared_apache_conf_file).to_s
68
+
69
+ debug "chmod g+w #{fetch(:shared_apache_conf_file)}"
70
+ execute "chmod g+w #{fetch(:shared_apache_conf_file)}"
71
+
72
+ app_domain = fetch(:app_domain)
73
+ server_name = app_domain.split('/')[2]
74
+
75
+ execute "sed -i 's|<<APP_DOMAIN>>|#{app_domain}|g' #{fetch(:shared_apache_conf_file)}"
76
+ execute "sed -i 's|<<SERVER_NAME>>|#{server_name}|g' #{fetch(:shared_apache_conf_file)}"
77
+
78
+ execute "#{sudo_cmd} ln -sfn #{fetch(:shared_apache_conf_file)} /etc/httpd/conf.d/"
79
+
80
+ debug '#' * 50
81
+ end
82
+ end
83
+
84
+ # desc 'Configure (HTTPS) Apache Application configuration files'
85
+ task :configure_app_ssl_conf_file do
86
+ on roles(:app) do
87
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
88
+
89
+ debug '#' * 50
90
+ debug 'Configure (HTTPS) Apache Application configuration files'
91
+
92
+ set :shared_apache_conf_ssl_file, "#{fetch(:shared_apache_path)}/app_#{fetch(:app_name_uri)}_ssl.conf"
93
+ http_ssl_file = File.expand_path('../../recipes/co7/apache_ssl.conf', __FILE__)
94
+ upload! StringIO.new(File.read(http_ssl_file)), fetch(:shared_apache_conf_ssl_file).to_s
95
+
96
+ debug "chmod g+w #{fetch(:shared_apache_conf_ssl_file)}"
97
+ execute "chmod g+w #{fetch(:shared_apache_conf_ssl_file)}"
98
+
99
+ execute "sed -i 's/<<APPLICATION_NAME>>/#{fetch(:app_name_uri)}/g' #{fetch(:shared_apache_conf_ssl_file)}"
100
+ execute "sed -i 's/<<ENVIRONMENT>>/#{fetch(:environment)}/g' #{fetch(:shared_apache_conf_ssl_file)}"
101
+
102
+ execute "#{sudo_cmd} ln -sfn #{fetch(:shared_apache_conf_ssl_file)} /etc/httpd/conf.d/"
103
+
104
+ debug '#' * 50
105
+ end
106
+ end
107
+
108
+ desc 'Update httpd.conf to secure apache server'
109
+ task :secure_apache do
110
+ on roles(:web) do
111
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
112
+
113
+ debug '#' * 50
114
+ debug 'Update httpd.conf to secure apache server'
115
+
116
+ set :httpd_conf_file, '/etc/httpd/conf/httpd.conf'
117
+
118
+ # Replace the original Apache configuration file
119
+ if remote_file_exists?('/etc/httpd/conf/httpd.conf_bck')
120
+ info 'Apache original configuration file already backed up at: /etc/httpd/conf/httpd.conf_bck'
121
+ else
122
+ execute "#{sudo_cmd} cp -f #{fetch(:httpd_conf_file)} /etc/httpd/conf/httpd.conf_bck"
123
+ info 'Apache original configuration file backed up at: /etc/httpd/conf/httpd.conf_bck'
124
+ end
125
+
126
+ # Create a temporary copy of the Apache configuration file
127
+ set :tmp_httpd_file, '/tmp/httpd.conf'
128
+ httpd_safe_file = File.expand_path('../../recipes/co7/httpd.conf', __FILE__)
129
+
130
+ upload! StringIO.new(File.read(httpd_safe_file)), fetch(:tmp_httpd_file).to_s
131
+
132
+ # Replace the original Apache configuration file
133
+ execute "#{sudo_cmd} mv -f #{fetch(:tmp_httpd_file)} #{fetch(:httpd_conf_file)}"
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,244 @@
1
+ namespace :apache do
2
+ desc 'Configure Apache configuration files'
3
+ task :configure do
4
+ on roles(:app) do
5
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
6
+
7
+ set :shared_path, "#{fetch(:deploy_to)}/shared"
8
+ set :shared_apache_path, "#{fetch(:shared_path)}/apache"
9
+
10
+ invoke 'apache:create_apache_shared_folder'
11
+ invoke 'apache:configure_app_conf_file'
12
+ invoke 'apache:configure_app_ssl_conf_file'
13
+
14
+ if remote_file_exists?('/etc/httpd/conf.d/ssl.conf')
15
+ execute "#{sudo_cmd} mv /etc/httpd/conf.d/ssl.conf /etc/httpd/conf.d/ssl.conf_bck"
16
+ end
17
+ end
18
+ end
19
+
20
+ # desc 'Configure (HTTP) Apache Application configuration files'
21
+ task :configure_app_conf_file do
22
+ on roles(:app) do
23
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
24
+
25
+ debug '#' * 50
26
+ debug 'Configure (HTTP) Apache Application configuration files'
27
+
28
+ set :shared_apache_conf_file, "#{fetch(:shared_apache_path)}/app_#{fetch(:app_name_uri)}.conf"
29
+ http_file = File.expand_path('../../recipes/apache_http.conf', __FILE__)
30
+ upload! StringIO.new(File.read(http_file)), fetch(:shared_apache_conf_file).to_s
31
+
32
+ debug "chmod g+w #{fetch(:shared_apache_conf_file)}"
33
+ execute "chmod g+w #{fetch(:shared_apache_conf_file)}"
34
+
35
+ passenger_root = get_command_output('/usr/local/rvm/bin/rvm default do passenger-config --root')
36
+ ruby_path = "/#{passenger_root.split('/')[1..5].join('/')}/wrappers/ruby"
37
+ app_domain = fetch(:app_domain)
38
+ server_name = app_domain.split('/')[2]
39
+
40
+ debug "sed -i 's|<<PASSENGER_ROOT>>|#{passenger_root}|g' #{fetch(:shared_apache_conf_file)}"
41
+ execute "sed -i 's|<<PASSENGER_ROOT>>|#{passenger_root}|g' #{fetch(:shared_apache_conf_file)}"
42
+
43
+ execute "sed -i 's|<<RUBY_PATH>>|#{ruby_path}|g' #{fetch(:shared_apache_conf_file)}"
44
+ execute "sed -i 's|<<APP_DOMAIN>>|#{app_domain}|g' #{fetch(:shared_apache_conf_file)}"
45
+ execute "sed -i 's|<<SERVER_NAME>>|#{server_name}|g' #{fetch(:shared_apache_conf_file)}"
46
+
47
+ execute "#{sudo_cmd} ln -sfn #{fetch(:shared_apache_conf_file)} /etc/httpd/conf.d/"
48
+
49
+ debug '#' * 50
50
+ end
51
+ end
52
+
53
+ # desc 'Configure (HTTPS) Apache Application configuration files'
54
+ task :configure_app_ssl_conf_file do
55
+ on roles(:app) do
56
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
57
+
58
+ debug '#' * 50
59
+ debug 'Configure (HTTPS) Apache Application configuration files'
60
+
61
+ set :shared_apache_conf_ssl_file, "#{fetch(:shared_apache_path)}/app_#{fetch(:app_name_uri)}_ssl.conf"
62
+ http_ssl_file = File.expand_path('../../recipes/apache_ssl.conf', __FILE__)
63
+ upload! StringIO.new(File.read(http_ssl_file)), fetch(:shared_apache_conf_ssl_file).to_s
64
+
65
+ debug "chmod g+w #{fetch(:shared_apache_conf_ssl_file)}"
66
+ execute "chmod g+w #{fetch(:shared_apache_conf_ssl_file)}"
67
+
68
+ server_name = string_between_markers(fetch(:app_domain), '://', '/')
69
+
70
+ execute "sed -i 's/<<SERVER_NAME>>/#{server_name}/g' #{fetch(:shared_apache_conf_ssl_file)}"
71
+ execute "sed -i 's/<<APPLICATION_NAME>>/#{fetch(:app_name_uri)}/g' #{fetch(:shared_apache_conf_ssl_file)}"
72
+ execute "sed -i 's/<<ENVIRONMENT>>/#{fetch(:environment)}/g' #{fetch(:shared_apache_conf_ssl_file)}"
73
+
74
+ execute "#{sudo_cmd} ln -sfn #{fetch(:shared_apache_conf_ssl_file)} /etc/httpd/conf.d/"
75
+
76
+ debug '#' * 50
77
+ end
78
+ end
79
+
80
+ desc 'Update httpd.conf to secure apache server'
81
+ task :secure_apache do
82
+ on roles(:web) do
83
+ sudo_cmd = "echo #{fetch(:password)} | sudo -S"
84
+
85
+ debug '#' * 50
86
+ debug 'Update httpd.conf to secure apache server'
87
+
88
+ set :httpd_conf_file, '/etc/httpd/conf/httpd.conf'
89
+
90
+ # Replace the original Apache configuration file
91
+ if remote_file_exists?('/etc/httpd/conf/httpd.conf_bck')
92
+ info 'Apache original configuration file already backed up at: /etc/httpd/conf/httpd.conf_bck'
93
+ else
94
+ execute "#{sudo_cmd} cp -f #{fetch(:httpd_conf_file)} /etc/httpd/conf/httpd.conf_bck"
95
+ info 'Apache original configuration file backed up at: /etc/httpd/conf/httpd.conf_bck'
96
+ end
97
+
98
+ # The ServerSignature directive allows the configuration of a trailing footer line under server-generated docs
99
+ # Options: On | Off | EMail
100
+ # More details: http://httpd.apache.org/docs/current/mod/core.html#serversignature
101
+ set :server_signature_off, get_num_occurrences_in_file(fetch(:httpd_conf_file), 'ServerSignature Off')
102
+
103
+ if fetch(:server_signature_off) == 1
104
+ info 'ServerSignature Off is already set'
105
+
106
+ else
107
+ set :num_replacements, 0
108
+ %w(On Off EMail).each do |option|
109
+ set :server_signature_option,
110
+ get_num_occurrences_in_file(fetch(:httpd_conf_file), "ServerSignature #{option}")
111
+
112
+ if fetch(:server_signature_option) == 1
113
+ info "sed -i 's/ServerSignature #{option}/ServerSignature Off/g' #{fetch(:httpd_conf_file)}"
114
+ execute "#{sudo_cmd} sed -i 's/ServerSignature #{option}/ServerSignature Off/g' #{fetch(:httpd_conf_file)}"
115
+ set :num_replacements, fetch(:num_replacements) + 1
116
+ end
117
+ end
118
+
119
+ error 'ServerSignature was not found' if fetch(:num_replacements).zero?
120
+ end
121
+
122
+ # Don't give away too much information about all the subcomponents we are running.
123
+ #
124
+ # Options: Major|Minor|Min[imal]|Prod[uctOnly]|OS|Full
125
+ # More details: http://httpd.apache.org/docs/current/mod/core.html#servertokens
126
+ set :server_token_prod, get_num_occurrences_in_file(fetch(:httpd_conf_file), 'ServerTokens Prod')
127
+ if fetch(:server_token_prod) == 1
128
+ info 'ServerTokens Prod is already set'
129
+ else
130
+ set :num_replacements, 0
131
+ %w(Major Minor Minimal Min ProductOnly Prod OS Full).each do |option|
132
+ set :server_token_option, get_num_occurrences_in_file(fetch(:httpd_conf_file), "ServerTokens #{option}")
133
+
134
+ next unless fetch(:server_token_option) == 1
135
+
136
+ # Then, only if fetch(:server_token_option) == 1
137
+ info "sed -i 's/ServerTokens #{option}/ServerTokens Prod/g' #{fetch(:httpd_conf_file)}"
138
+ execute "#{sudo_cmd} sed -i 's/ServerTokens #{option}/ServerTokens Prod/g' #{fetch(:httpd_conf_file)}"
139
+ set :num_replacements, fetch(:num_replacements) + 1
140
+ end
141
+
142
+ error 'ServerTokens was not found' if fetch(:num_replacements).zero?
143
+ end
144
+
145
+ # Do not allow browsing outside the document root
146
+ #
147
+ # <Directory />
148
+ # Order Deny,Allow
149
+ # Deny from all
150
+ # Options None
151
+ # AllowOverride None
152
+ # </Directory>
153
+ #
154
+ message_line1 = '# Default Directory configuration changed via Capistrano.'
155
+
156
+ set :server_dir_secure_configuration, get_num_occurrences_in_file(fetch(:httpd_conf_file), message_line1)
157
+
158
+ if fetch(:server_token_prod) == 1
159
+ info 'The correct directory configuration is already correctly set'
160
+ else
161
+
162
+ set :tmp_dir_original_config, '/tmp/tmp_dir_original_config.conf'
163
+ set :tmp_dir_original_commented_config, '/tmp/tmp_dir_original_commented_config.conf'
164
+ set :tmp_dir_new_config, '/tmp/tmp_dir_new_config.conf'
165
+
166
+ # Create a temporary copy of the Apache configuration file
167
+ set :tmp_httpd_file, '/tmp/httpd.conf'
168
+ execute :cp, '-f', "#{fetch(:httpd_conf_file)} #{fetch(:tmp_httpd_file)}"
169
+
170
+ set :grep_for_directory, "grep -Pzo '^([ ]*<Directory />[ ]*)(\\n.*)+(\\n[ ]*</Directory>[ ]*)(\\n){1}$' "\
171
+ "#{fetch(:tmp_httpd_file)}"
172
+
173
+ # How many lines have the original configuration
174
+ command = "#{fetch(:grep_for_directory)} | grep -n '</Directory>' | head -n 1 | cut -d ':' -f1"
175
+ set :def_directory_num_lines, get_command_output(command).to_i
176
+ debug "Original configuration has #{fetch(:def_directory_num_lines)} lines."
177
+
178
+ # Saves to a file the original configuration
179
+ command = "#{fetch(:grep_for_directory)} | "\
180
+ "head -n #{fetch(:def_directory_num_lines)} > #{fetch(:tmp_dir_original_config)}"
181
+ debug command
182
+ execute command
183
+
184
+ # Saves to a file the original configuration commented
185
+ execute :cp, '-f', "#{fetch(:tmp_dir_original_config)} #{fetch(:tmp_dir_original_commented_config)}"
186
+ execute "sed -e 's/^/#/' -i #{fetch(:tmp_dir_original_commented_config)}"
187
+
188
+ # Save to a file the new desired configuration
189
+ new_directory_configs = <<-EOF
190
+
191
+ # Do not allow browsing outside the document root
192
+ <Directory />
193
+ Order Deny,Allow
194
+ Deny from all
195
+ Options None
196
+ AllowOverride None
197
+ </Directory>
198
+
199
+ EOF
200
+ upload! StringIO.new(new_directory_configs), fetch(:tmp_dir_new_config).to_s
201
+
202
+ # Update the new configuration file to have the original configuration commented
203
+ debug "cat #{fetch(:tmp_dir_new_config)} >> #{fetch(:tmp_dir_original_commented_config)}"
204
+ execute "cat #{fetch(:tmp_dir_new_config)} >> #{fetch(:tmp_dir_original_commented_config)}"
205
+ execute "mv -f #{fetch(:tmp_dir_original_commented_config)} #{fetch(:tmp_dir_new_config)}"
206
+
207
+ # Generates the special SED parameter: 'N;' per line that should be replaced
208
+ special_sed_param = 'N;' * fetch(:def_directory_num_lines)
209
+ debug "Special sed parameter is: ''#{special_sed_param}''"
210
+
211
+ # Replace the old original directory configuration for a specific message (in the temporary file)
212
+ message_complete = "#{message_line1}\\n#\\n"
213
+ command_to_replace = "out=$(sed -e :a -e '$!N;s/\\n/.*/;ta' #{fetch(:tmp_dir_original_config)} | "\
214
+ "sed -e :a -e '$!N;s/\//./;ta'); sed -i '/<Directory .>.*/ {#{special_sed_param} "\
215
+ "s/'$out'/#{message_complete}/g}' #{fetch(:tmp_httpd_file)}"
216
+ debug command_to_replace
217
+ execute command_to_replace
218
+
219
+ # Search for the line where the message was inserted
220
+ command = "grep -n '#{message_line1}' #{fetch(:tmp_httpd_file)} | cut -d':' -f 1"
221
+ debug command
222
+ line_with_match = get_command_output(command).to_i
223
+ next_line = line_with_match + 1
224
+ debug "New configuration will be added to line #{next_line}"
225
+
226
+ # Inserts the new directory configuration (with the old configuration commented)
227
+ # in the line following the comment added before
228
+ command = "sed '#{next_line}r #{fetch(:tmp_dir_new_config)}' < #{fetch(:tmp_httpd_file)} "\
229
+ '> tmp_httpd_new_conf_merge.conf'
230
+
231
+ debug command
232
+ execute command
233
+ execute "mv -f tmp_httpd_new_conf_merge.conf #{fetch(:tmp_httpd_file)}"
234
+
235
+ # Replace the original Apache configuration file
236
+ execute "#{sudo_cmd} mv -f #{fetch(:tmp_httpd_file)} #{fetch(:httpd_conf_file)}"
237
+
238
+ # Remove all created temporary files
239
+ execute "rm -f #{fetch(:tmp_dir_original_config)} #{fetch(:tmp_dir_original_commented_config)} "\
240
+ "#{fetch(:tmp_dir_new_config)} #{fetch(:tmp_httpd_file)}"
241
+ end
242
+ end
243
+ end
244
+ end
@@ -159,7 +159,7 @@ namespace :load do
159
159
  # RVM related information
160
160
  set :rvm_type, -> { :system }
161
161
  set :rvm_ruby_version, -> { ask('Please specify the Ruby version (i.e. 2.1.5)', '') }
162
- set :rvm_roles, [:app, :web]
162
+ set :rvm_roles, %i(app web)
163
163
  # set :rvm_custom_path, '~/.myveryownrvm' # only needed if not detected
164
164
 
165
165
  # Apache related information
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-exfel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.14
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luis Maia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-20 00:00:00.000000000 Z
11
+ date: 2017-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -54,15 +54,22 @@ files:
54
54
  - Rakefile
55
55
  - capistrano-exfel.gemspec
56
56
  - lib/capistrano/exfel.rb
57
+ - lib/capistrano/exfel/co7.rb
57
58
  - lib/capistrano/exfel/sl6.rb
58
59
  - lib/capistrano/exfel/version.rb
59
60
  - lib/capistrano/recipes/apache_http.conf
60
61
  - lib/capistrano/recipes/apache_ssl.conf
62
+ - lib/capistrano/recipes/co7/00-passenger.conf
63
+ - lib/capistrano/recipes/co7/apache_http.conf
64
+ - lib/capistrano/recipes/co7/apache_ssl.conf
65
+ - lib/capistrano/recipes/co7/httpd.conf
61
66
  - lib/capistrano/recipes/config/database_mysql.yml
62
67
  - lib/capistrano/recipes/config/database_postgresql.yml
63
68
  - lib/capistrano/recipes/config/database_sqlite.yml
64
69
  - lib/capistrano/recipes/config/secrets_example.yml
65
70
  - lib/capistrano/tasks/apache.rake
71
+ - lib/capistrano/tasks/apache_co7.rake
72
+ - lib/capistrano/tasks/apache_sl6.rake
66
73
  - lib/capistrano/tasks/app_home.rake
67
74
  - lib/capistrano/tasks/application.rake
68
75
  - lib/capistrano/tasks/database.rake