capistrano-custom-maintenance 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-custom-maintenance.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Yamashita Yuu
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 ADDED
@@ -0,0 +1,67 @@
1
+ # capistrano-custom-maintenance
2
+
3
+ a customizable capistrano maintenance recipe.
4
+
5
+ this recipe has backward compatibility with original capistrano's maintenance features.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'capistrano-custom-maintenance'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install capistrano-custom-maintenance
20
+
21
+ ## Usage
22
+
23
+ Add following in you `config/deploy.rb`.
24
+
25
+ # in "config/deploy.rb"
26
+ require 'capistrano-custom-maintenance'
27
+
28
+ Now you can entering/leaving maintenance
29
+
30
+ $ cap deploy:web:disable # <-- entering maintenance
31
+ $ cap deploy:web:enable # <-- leaving maintenance
32
+
33
+ If you prefer JSON response for maintenance page, you can do it with configuring as following.
34
+
35
+ # in "config/deploy.rb"
36
+ require 'capistrano-custom-maintenance'
37
+ set(:maintenance_content_type, 'application/json')
38
+
39
+ Following options are available to manage your maintenance.
40
+
41
+ * `:maintenance_basename` - basename of your maintenance page. use `maintenance` by default.
42
+ * `:maintenance_filename` - filename of maintenance document, not including path part.
43
+ * `:maintenance_suffix` - suffix of maintenance document. guessed from content-type by default.
44
+ * `:maintenance_content_type` - the `Content-Type` of maintenance page. use `text/html` by default.
45
+ * `:maintenance_reason` - the reason of maintenance. use `ENV['REASON']` by default.
46
+ * `:maintenance_deadline` - the deadline of maintenance. use `ENV['UNTIL']` by default.
47
+ * `:maintenance_document_path` - the path to the maintenance page on httpd.
48
+ * `:maintenance_system_path` - the path to the maintenance page.
49
+ * `:maintenance_template_path` - the path to the maintenance templates.
50
+ * `:maintenance_template` - the path to the template of maintenance page.
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
59
+
60
+ ## Author
61
+
62
+ - YAMASHITA Yuu (https://github.com/yyuu)
63
+ - Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
64
+
65
+ ## License
66
+
67
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/capistrano-custom-maintenance/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Yamashita Yuu"]
6
+ gem.email = ["yamashita@geishatokyo.com"]
7
+ gem.description = %q{a customizable capistrano maintenance recipe.}
8
+ gem.summary = %q{a customizable capistrano maintenance recipe.}
9
+ gem.homepage = "https://github.com/yyuu/capistrano-custom-maintenance"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capistrano-custom-maintenance"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Capistrano::CustomMaintenance::VERSION
17
+
18
+ gem.add_dependency("capistrano")
19
+ gem.add_dependency("json")
20
+ gem.add_dependency("mime-types")
21
+ end
@@ -0,0 +1,8 @@
1
+ require "capistrano-custom-maintenance/deploy"
2
+ require "capistrano-custom-maintenance/version"
3
+
4
+ module Capistrano
5
+ module CustomMaintenance
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,78 @@
1
+
2
+ require 'erb'
3
+ require 'json'
4
+ require 'mime/types'
5
+
6
+ module Capistrano
7
+ module CustomMaintenance
8
+ def self.extended(configuration)
9
+ configuration.load {
10
+ namespace(:deploy) {
11
+ _cset(:maintenance_template_path, File.dirname(__FILE__), 'templates')
12
+ _cset(:maintenance_template) {
13
+ ts = [
14
+ File.join(maintenance_template_path, "#{maintenance_basename}.#{maintenance_suffix}.erb"),
15
+ File.join(maintenance_template_path, "#{maintenance_basename}.erb"),
16
+ ]
17
+ ts << File.join(maintenance_template_path, "#{maintenance_basename}.rhtml") if maintenance_suffix == 'html'
18
+ xs = ts.select { |t| File.exist?(t) }
19
+ unless xs.empty?
20
+ xs.first
21
+ else
22
+ abort("No such template found: #{ts.join(', ')}")
23
+ end
24
+ }
25
+ _cset(:maintenance_content_type, 'text/html')
26
+ _cset(:maintenance_suffix) { # suffix of maintenance document. guessed from content-type by default.
27
+ type, = MIME::Types[maintenance_content_type]
28
+ type.extensions.first
29
+ }
30
+ _cset(:maintenance_filename) { # filename of maintenance document, not including path part
31
+ "#{maintenance_basename}.#{maintenance_suffix}"
32
+ }
33
+ _cset(:maintenance_system_path) { # actual path
34
+ File.join(shared_path, maintenance_document_path)
35
+ }
36
+ _cset(:maintenance_document_path) { # virtual path on httpd
37
+ File.join('/system', maintenance_filename)
38
+ }
39
+
40
+ _cset(:maintenance_timestamp) {
41
+ Time.now
42
+ }
43
+ _cset(:maintenance_reason) {
44
+ ENV.fetch('REASON', "maintenance")
45
+ }
46
+ _cset(:maintenance_deadline) {
47
+ ENV.fetch('UNTIL', "shortly")
48
+ }
49
+
50
+ namespace(:web) {
51
+ task(:disable, :roles => :web, :except => { :no_release => true }) {
52
+ on_rollback {
53
+ run("rm -f #{maintenance_system_path}")
54
+ }
55
+
56
+ reason = maintenance_reason
57
+ deadline = maintenance_deadline
58
+ template = File.read(maintenance_template)
59
+ result = ERB.new(template).result(binding)
60
+
61
+ put(result, maintenance_system_path, :mode => 0644)
62
+ }
63
+
64
+ task(:enable, :roles => :web, :except => { :no_release => true }) {
65
+ run("rm -f #{maintenance_system_path}")
66
+ }
67
+ }
68
+ }
69
+ }
70
+ end
71
+ end
72
+ end
73
+
74
+ if Capistrano::Configuration.instance
75
+ Capistrano::Configuration.instance.extend(Capistrano::CustomMaintenance)
76
+ end
77
+
78
+ # vim:set ft=ruby :
@@ -0,0 +1,53 @@
1
+
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
3
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
4
+
5
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
+
7
+ <head>
8
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
9
+ <title>System down for maintenance</title>
10
+
11
+ <style type="text/css">
12
+ div.outer {
13
+ position: absolute;
14
+ left: 50%;
15
+ top: 50%;
16
+ width: 500px;
17
+ height: 300px;
18
+ margin-left: -260px;
19
+ margin-top: -150px;
20
+ }
21
+
22
+ .DialogBody {
23
+ margin: 0;
24
+ padding: 10px;
25
+ text-align: left;
26
+ border: 1px solid #ccc;
27
+ border-right: 1px solid #999;
28
+ border-bottom: 1px solid #999;
29
+ background-color: #fff;
30
+ }
31
+
32
+ body { background-color: #fff; }
33
+ </style>
34
+ </head>
35
+
36
+ <body>
37
+
38
+ <div class="outer">
39
+ <div class="DialogBody" style="text-align: center;">
40
+ <div style="text-align: center; width: 200px; margin: 0 auto;">
41
+ <p style="color: red; font-size: 16px; line-height: 20px;">
42
+ The system is down for <%= maintenance_reason %>
43
+ as of <%= maintenance_timestamp.strftime("%H:%M %Z") %>.
44
+ </p>
45
+ <p style="color: #666;">
46
+ It'll be back <%= maintenance_deadline %>.
47
+ </p>
48
+ </div>
49
+ </div>
50
+ </div>
51
+
52
+ </body>
53
+ </html>
@@ -0,0 +1,8 @@
1
+ <%=
2
+ {
3
+ "type" => "maintenance",
4
+ "timestamp" => maintenance_timestamp,
5
+ "reason" => maintenance_reason,
6
+ "deadline" => maintenance_deadline,
7
+ }.to_json()
8
+ %>
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module CustomMaintenance
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-custom-maintenance
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Yamashita Yuu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: mime-types
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: a customizable capistrano maintenance recipe.
63
+ email:
64
+ - yamashita@geishatokyo.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - capistrano-custom-maintenance.gemspec
75
+ - lib/capistrano-custom-maintenance.rb
76
+ - lib/capistrano-custom-maintenance/deploy.rb
77
+ - lib/capistrano-custom-maintenance/templates/maintenance.html.erb
78
+ - lib/capistrano-custom-maintenance/templates/maintenance.json.erb
79
+ - lib/capistrano-custom-maintenance/version.rb
80
+ homepage: https://github.com/yyuu/capistrano-custom-maintenance
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.23
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: a customizable capistrano maintenance recipe.
104
+ test_files: []
105
+ has_rdoc: