capistrano-maintenance 0.0.5 → 1.0.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: bfa25fd8964b5920d1f82d422f2671eeb7dadd36
4
- data.tar.gz: 569d7a6c4610b3f245701ebefce92837b5e2ad8c
3
+ metadata.gz: 4840f0379ec3fc55ca13c69663bfc4cd14132c76
4
+ data.tar.gz: 6fa9b428b819ad1619a86882820622857b41b420
5
5
  SHA512:
6
- metadata.gz: 0579666e4ec68db548a31483c4f23e66e7ae42a1c650eb4c73b20e5bd00c6a885682e339fd997c1f4abd8511dd0c2bba5d5ec0d15fd9e58b775d1e4ebf7bcf43
7
- data.tar.gz: d57033fe692fb3e19b2e224ab053a4d10de5aac12af5cb4748d86aaef2d5d6440c0725e837de713bf4fd1af944bcc211e3ddabc97ff869a409c11faa0ad6ee6e
6
+ metadata.gz: 978014eaa1c344105af9f482b0e26894fecac52add57f45a12c9636138d5eba52357fed2398cb27bb410dfb18bd50aa6dbc98ce9cba21f06d54c96cfb344d31f
7
+ data.tar.gz: f24d03db3e71fe4416d5297df6ba6ae95af58136a1a1a0394fa7ff6a7cdd07a2d22f9d53392a2bb99742b52e07ff2167cca223a38604bc47a3f779cbfb746df0
data/.gitignore CHANGED
@@ -2,8 +2,12 @@
2
2
  *.rbc
3
3
  .bundle
4
4
  .config
5
- coverage
5
+ .yardoc
6
+ Gemfile.lock
6
7
  InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
7
11
  lib/bundler/man
8
12
  pkg
9
13
  rdoc
@@ -11,9 +15,3 @@ spec/reports
11
15
  test/tmp
12
16
  test/version_tmp
13
17
  tmp
14
-
15
- # YARD artifacts
16
- .yardoc
17
- _yardoc
18
- doc/
19
- Gemfile.lock
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
3
2
 
4
- group :development do
5
- gem 'bumpy'
6
- end
3
+ # Specify your gem's dependencies in capistrano-maintenance.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kir Shatrov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,83 +1,102 @@
1
- Capistrano 2 Maintenance Extension
2
- ==================================
1
+ # Capistrano::Maintenance
3
2
 
4
- This gem simply offers the recently removed `deploy:web:disable` and `deploy:web:enable` tasks to your Capistrano 2 deployment.
3
+ ## Installation
5
4
 
6
- **NOTE** This version only works with Capistrano 2.x. For a Capistrano 3 compatible version please use [the official extension](https://github.com/capistrano/maintenance).
5
+ Add this line to your application's Gemfile:
7
6
 
8
- Usage
9
- -----
7
+ gem 'capistrano', '~> 3.0'
8
+ gem 'capistrano-maintenance', github: "capistrano/maintenance", require: false
10
9
 
11
- Install the gem via rubygems:
12
10
 
13
- ```sh
14
- gem install capistrano-maintenance --version=0.0.5
15
- ```
11
+ And then execute:
16
12
 
17
- or use bundler:
13
+ $ bundle
18
14
 
19
- ```ruby
20
- # Gemfile
21
- gem 'capistrano-maintenance', '0.0.5', group: 'development'
22
- ```
15
+ Or install it yourself:
23
16
 
24
- ```sh
25
- bundle install
26
- ```
17
+ $ gem install capistrano-maintenance
27
18
 
28
- And put this line into your deploy.rb file:
19
+ ## Usage
29
20
 
30
- ```ruby
31
- require 'capistrano/maintenance'
32
- ```
21
+ Before using the maintenance tasks, you need to configure your webserver. How you do this depends on how your server is configured, but the following examples should help you on your way.
22
+
23
+ Application servers such as [Passenger](https://www.phusionpassenger.com) and [unicorn](http://unicorn.bogomips.org) requires you to set your public web directory to `current/public`. Both examples below are compatible with this setup.
33
24
 
34
- Now, you can disable the web:
25
+ Here is an example config for **nginx**. Note that this is just a part of the complete config, and will probably require modifications.
35
26
 
36
- ```sh
37
- cap deploy:web:disable
27
+ ```
28
+ error_page 503 @503;
29
+
30
+ # Return a 503 error if the maintenance page exists.
31
+ if (-f /var/www/domain.com/shared/public/system/maintenance.html) {
32
+ return 503;
33
+ }
34
+
35
+ location @503 {
36
+ # Serve static assets if found.
37
+ if (-f $request_filename) {
38
+ break;
39
+ }
40
+
41
+ # Set root to the shared directory.
42
+ root /var/www/domain.com/shared/public;
43
+ rewrite ^(.*)$ /system/maintenance.html break;
44
+ }
38
45
  ```
39
46
 
40
- You can also specify a string to specify reason and how long it is until:
47
+ And here is an example config for **Apache**. This will also need to be modified.
41
48
 
42
- ```sh
43
- cap deploy:web:disable REASON="For server upgrades" UNTIL="3AM EST"
49
+ ```
50
+ # Create an alias to the maintenance page used as error document.
51
+ Alias "/error" "/var/www/domain.com/shared/public/system/"
52
+ ErrorDocument 503 /error/maintenance.html
53
+
54
+ # Return 503 error if the maintenance page exists.
55
+ RewriteCond /var/www/domain.com/shared/public/system/maintenance.html -f
56
+ RewriteRule !^/error/maintenance.html - [L,R=503]
57
+
58
+ # Redirect all non-static requests to unicorn (or similar).
59
+ # Will not redirect any requests if the maintenance page exists.
60
+ RewriteCond /var/www/domain.com/shared/public/system/maintenance.html !-f
61
+ RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
62
+ RewriteRule ^/(.*)$ balancer://unicornserver%{REQUEST_URI} [P,QSA,L]
44
63
  ```
45
64
 
46
- When maintenance is done, you can enable the web:
65
+ You can now require the gem in your `Capfile`:
47
66
 
48
- ```sh
49
- cap deploy:web:enable
50
- ```
67
+ require 'capistrano/maintenance'
51
68
 
52
- If you are using [multistage capistrano](https://github.com/capistrano/capistrano/wiki/2.x-Multistage-Extension), you'll also need to include the stage before `deploy:web:disable` and `deploy:web:enable`:
69
+ ### Enable task
53
70
 
54
- ```sh
55
- cap production deploy:web:disable
56
- cap production deploy:web:enable
57
- ```
71
+ Present a maintenance page to visitors. Disables your application's web
72
+ interface by writing a "#{maintenance_basename}.html" file to each web server. The
73
+ servers must be configured to detect the presence of this file, and if
74
+ it is present, always display it instead of performing the request.
58
75
 
59
- Configuration
60
- -------------
76
+ By default, the maintenance page will just say the site is down for
77
+ "maintenance", and will be back "shortly", but you can customize the
78
+ page by specifying the REASON and UNTIL environment variables:
61
79
 
62
- Everything should work out of the box general, but there are some additional adjustments you can make in your deploy.rb.
80
+ cap maintenance:enable REASON="hardware upgrade" UNTIL="12pm Central Time"
63
81
 
64
- ```ruby
65
- # change the default filename from maintenance.html to disabled.html
66
- set :maintenance_basename, 'disabled'
82
+ You can use a different template for the maintenance page by setting the
83
+ `:maintenance_template_path` variable in your deploy.rb file. The template file
84
+ should either be a plaintext or an erb file.
67
85
 
68
- # change default directory from default of #{shared_path}/system
69
- set :maintenance_dirname, "#{shared_path}/public/system"
86
+ Further customization will require that you write your own task.
70
87
 
71
- # use local template instead of included one with capistrano-maintenance
72
- set :maintenance_template_path, 'app/views/maintenance.html.erb'
88
+ ### Disable task
73
89
 
74
- # disable the warning on how to configure your server
75
- set :maintenance_config_warning, false
76
- ```
90
+ cap maintenance:disable
77
91
 
78
- For your custom maintenance template, you have access to the following variables, if they're defined:
92
+ Makes the application web-accessible again. Removes the
93
+ "#{maintenance_basename}.html" page generated by maintenance:disable, which (if your
94
+ web servers are configured correctly) will make your application web-accessible again.
79
95
 
80
- * reason
81
- * deadline
96
+ ## Contributing
82
97
 
83
- These are the environment variables passed in via REASON="something" and UNTIL="later"
98
+ 1. Fork it
99
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
100
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
101
+ 4. Push to the branch (`git push origin my-new-feature`)
102
+ 5. Create new Pull Request
data/Rakefile CHANGED
@@ -1,10 +1 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/gem_helper'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
-
8
- Bundler::GemHelper.install_tasks
9
-
10
- task :default => :build
1
+ require "bundler/gem_tasks"
@@ -1,20 +1,25 @@
1
- # encoding: utf-8
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "capistrano/maintenance/version"
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano-maintenance/version'
4
5
 
5
- Gem::Specification.new do |s|
6
- s.name = 'capistrano-maintenance'
7
- s.version = Capistrano::Maintenance::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.license = 'MIT'
10
- s.author = 'Thomas von Deyen'
11
- s.email = 'tvd@magiclabs.de'
12
- s.homepage = 'https://github.com/tvdeyen/capistrano-maintenance'
13
- s.summary = %q{Offers deploy:web:disable and deploy:web:enable tasks for Capistrano.}
14
- s.description = %q{The deploy:web tasks where removed from Capistrano core. This extension brings them back.}
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "capistrano-maintenance"
8
+ spec.version = CapistranoMaintenance::VERSION
9
+ spec.authors = ["Kir Shatrov"]
10
+ spec.email = ["shatrov@me.com"]
11
+ spec.description = %q{Maintenance Support for Capistrano 3}
12
+ spec.summary = %q{Enable and disabled tasks to show when your project is on maintenance}
13
+ spec.homepage = "https://github.com/capistrano/capistrano-maintenance"
14
+ spec.license = "MIT"
15
15
 
16
- s.files = `git ls-files`.split("\n")
17
- s.require_paths = ["lib"]
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
18
20
 
19
- s.add_dependency 'capistrano', ['~> 2.0']
21
+ spec.add_dependency "capistrano", ">= 3.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
20
25
  end
@@ -0,0 +1,3 @@
1
+ module CapistranoMaintenance
2
+ VERSION = "1.0.0"
3
+ end
@@ -1,94 +1 @@
1
- require 'capistrano'
2
-
3
- module Capistrano
4
- module Maintenance
5
-
6
- def self.load_into(configuration)
7
- configuration.load do
8
-
9
- _cset(:maintenance_dirname) { "#{shared_path}/system" }
10
- _cset :maintenance_basename, "maintenance"
11
- _cset(:maintenance_template_path) { File.join(File.dirname(__FILE__), "templates", "maintenance.html.erb") }
12
-
13
- namespace :deploy do
14
-
15
- namespace :web do
16
-
17
- desc <<-DESC
18
- Present a maintenance page to visitors. Disables your application's web \
19
- interface by writing a "#{maintenance_basename}.html" file to each web server. The \
20
- servers must be configured to detect the presence of this file, and if \
21
- it is present, always display it instead of performing the request.
22
-
23
- By default, the maintenance page will just say the site is down for \
24
- "maintenance", and will be back "shortly", but you can customize the \
25
- page by specifying the REASON and UNTIL environment variables:
26
-
27
- $ cap deploy:web:disable \\
28
- REASON="hardware upgrade" \\
29
- UNTIL="12pm Central Time"
30
-
31
- You can use a different template for the maintenance page by setting the \
32
- :maintenance_template_path variable in your deploy.rb file. The template file \
33
- should either be a plaintext or an erb file.
34
-
35
- Further customization will require that you write your own task.
36
- DESC
37
- task :disable, :roles => :web, :except => { :no_release => true } do
38
- require 'erb'
39
- on_rollback { run "rm -f #{maintenance_dirname}/#{maintenance_basename}.html" }
40
-
41
- if fetch(:maintenance_config_warning, true)
42
- warn <<-EOHTACCESS
43
-
44
- # Please add something like this to your site's Apache htaccess to redirect users to the maintenance page.
45
- # More Info: http://www.shiftcommathree.com/articles/make-your-rails-maintenance-page-respond-with-a-503
46
-
47
- ErrorDocument 503 /system/#{maintenance_basename}.html
48
- RewriteEngine On
49
- RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
50
- RewriteCond %{DOCUMENT_ROOT}/system/#{maintenance_basename}.html -f
51
- RewriteCond %{SCRIPT_FILENAME} !#{maintenance_basename}.html
52
- RewriteRule ^.*$ - [redirect=503,last]
53
-
54
- # Or if you are using Nginx add this to your server config:
55
-
56
- if (-f $document_root/system/maintenance.html) {
57
- return 503;
58
- }
59
- error_page 503 @maintenance;
60
- location @maintenance {
61
- rewrite ^(.*)$ /system/maintenance.html last;
62
- break;
63
- }
64
- EOHTACCESS
65
- end
66
-
67
- reason = ENV['REASON']
68
- deadline = ENV['UNTIL']
69
-
70
- template = File.read(maintenance_template_path)
71
- result = ERB.new(template).result(binding)
72
-
73
- put result, "#{maintenance_dirname}/#{maintenance_basename}.html", :mode => 0644
74
- end
75
-
76
- desc <<-DESC
77
- Makes the application web-accessible again. Removes the \
78
- "#{maintenance_basename}.html" page generated by deploy:web:disable, which (if your \
79
- web servers are configured correctly) will make your application \
80
- web-accessible again.
81
- DESC
82
- task :enable, :roles => :web, :except => { :no_release => true } do
83
- run "rm -f #{maintenance_dirname}/#{maintenance_basename}.html"
84
- end
85
- end
86
- end
87
- end
88
- end
89
- end
90
- end
91
-
92
- if Capistrano::Configuration.instance
93
- Capistrano::Maintenance.load_into(Capistrano::Configuration.instance)
94
- end
1
+ load File.expand_path("../tasks/maintenance.rake", __FILE__)
@@ -0,0 +1,33 @@
1
+ namespace :maintenance do
2
+ desc "Turn on maintenance mode"
3
+ task :enable do
4
+ on roles(:web) do
5
+ require 'erb'
6
+
7
+ reason = ENV['REASON']
8
+ deadline = ENV['UNTIL']
9
+
10
+ default_template = File.join(File.expand_path('../../templates', __FILE__), 'maintenance.html.erb')
11
+ template = fetch(:maintenance_template_path, default_template)
12
+ result = ERB.new(File.read(template)).result(binding)
13
+
14
+ rendered_path = "#{shared_path}/public/system/"
15
+ rendered_name = "#{fetch(:maintenance_basename, 'maintenance')}.html"
16
+
17
+ if test "[ ! -d #{rendered_path} ]"
18
+ info 'Creating missing directories.'
19
+ execute :mkdir, '-pv', rendered_path
20
+ end
21
+
22
+ upload!(StringIO.new(result), rendered_path + rendered_name)
23
+ execute "chmod 644 #{rendered_path + rendered_name}"
24
+ end
25
+ end
26
+
27
+ desc "Turn off maintenance mode"
28
+ task :disable do
29
+ on roles(:web) do
30
+ execute "rm -f #{shared_path}/public/system/#{fetch(:maintenance_basename, 'maintenance')}.html"
31
+ end
32
+ end
33
+ end
@@ -18,8 +18,8 @@
18
18
  <h1>Maintenance</h1>
19
19
 
20
20
  <p>The system is down for <%= reason ? reason : "maintenance" %><br>
21
- as of <%= Time.now.strftime("%H:%M %Z") %>.</p>
21
+ as of <%= Time.now.strftime("%F %H:%M %Z") %>.</p>
22
22
 
23
23
  <p>It'll be back <%= deadline ? deadline : "shortly" %>.</p>
24
24
  </body>
25
- </html>
25
+ </html>
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-maintenance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Thomas von Deyen
7
+ - Kir Shatrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -14,32 +14,62 @@ dependencies:
14
14
  name: capistrano
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '2.0'
27
- description: The deploy:web tasks where removed from Capistrano core. This extension
28
- brings them back.
29
- email: tvd@magiclabs.de
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Maintenance Support for Capistrano 3
56
+ email:
57
+ - shatrov@me.com
30
58
  executables: []
31
59
  extensions: []
32
60
  extra_rdoc_files: []
33
61
  files:
34
62
  - ".gitignore"
35
63
  - Gemfile
64
+ - LICENSE.txt
36
65
  - README.md
37
66
  - Rakefile
38
67
  - capistrano-maintenance.gemspec
68
+ - lib/capistrano-maintenance/version.rb
39
69
  - lib/capistrano/maintenance.rb
40
- - lib/capistrano/maintenance/version.rb
70
+ - lib/capistrano/tasks/maintenance.rake
41
71
  - lib/capistrano/templates/maintenance.html.erb
42
- homepage: https://github.com/tvdeyen/capistrano-maintenance
72
+ homepage: https://github.com/capistrano/capistrano-maintenance
43
73
  licenses:
44
74
  - MIT
45
75
  metadata: {}
@@ -59,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
89
  version: '0'
60
90
  requirements: []
61
91
  rubyforge_project:
62
- rubygems_version: 2.4.6
92
+ rubygems_version: 2.2.2
63
93
  signing_key:
64
94
  specification_version: 4
65
- summary: Offers deploy:web:disable and deploy:web:enable tasks for Capistrano.
95
+ summary: Enable and disabled tasks to show when your project is on maintenance
66
96
  test_files: []
@@ -1,5 +0,0 @@
1
- module Capistrano
2
- module Maintenance
3
- VERSION = "0.0.5"
4
- end
5
- end