turnout 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +19 -0
- data/README.markdown +82 -0
- data/lib/rack/turnout.rb +8 -0
- data/lib/tasks/maintenance.rake +23 -1
- data/lib/turnout/version.rb +1 -1
- metadata +6 -4
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2011 by Biola University
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
Turnout
|
2
|
+
=======
|
3
|
+
Turnout is a [Ruby on Rails](http://rubyonrails.org) engine with a [Rack](http://rack.rubyforge.org/) component that allows you to put your Rails app in maintenance mode.
|
4
|
+
|
5
|
+
Features
|
6
|
+
========
|
7
|
+
* Easy installation
|
8
|
+
* Rake commands to turn maintenance mode on and off
|
9
|
+
* Easily provide a reason for each downtime without editing the maintenance.html file
|
10
|
+
* Allow certain IPs or IP ranges to bypass the maintenance page
|
11
|
+
* Allow certain paths to be accessible during maintenance
|
12
|
+
* Easily override the default maintenance.html file with your own
|
13
|
+
* Simple [YAML](http://yaml.org) based config file for easy activation, deactivation and configuration without the rake commands
|
14
|
+
|
15
|
+
Installation
|
16
|
+
============
|
17
|
+
In your Gemfile add:
|
18
|
+
|
19
|
+
gem 'turnout'
|
20
|
+
|
21
|
+
then run
|
22
|
+
|
23
|
+
bundle install
|
24
|
+
|
25
|
+
Activation
|
26
|
+
==========
|
27
|
+
|
28
|
+
rake maintenance:start
|
29
|
+
|
30
|
+
or
|
31
|
+
|
32
|
+
rake maintenance:start reason="Somebody googled Google!"
|
33
|
+
|
34
|
+
or
|
35
|
+
|
36
|
+
rake maintenance:start allowed_paths="/login,^/faqs/[0-9]*"
|
37
|
+
|
38
|
+
or
|
39
|
+
|
40
|
+
rake maintenance:start allowed_ips="4.8.15.16"
|
41
|
+
|
42
|
+
or
|
43
|
+
|
44
|
+
rake maintenance:start reason="Someone told me I should type <code>sudo rm -rf /</code>" allowed_paths="^/help,^/contact_us" allowed_ips="127.0.0.1,192.168.0.0/24"
|
45
|
+
|
46
|
+
Notes
|
47
|
+
-----
|
48
|
+
* The `reason` parameter can contain HTML
|
49
|
+
* Multiple `allowed_paths` and `allowed_ips` can be given. Just comma separate them.
|
50
|
+
* All `allowed_paths` are treated as regular expressions.
|
51
|
+
* If you need to use a comma in an `allowed_paths` regular expression just escape it with a backslash: `\,`.
|
52
|
+
* IP ranges can be given to `allowed_ips` using [CIDR notation](http://en.wikipedia.org/wiki/CIDR_notation).
|
53
|
+
|
54
|
+
Deactivation
|
55
|
+
============
|
56
|
+
|
57
|
+
rake maintenance:end
|
58
|
+
|
59
|
+
Customization
|
60
|
+
=============
|
61
|
+
|
62
|
+
A [default maintenance page](https://github.com/biola/turnout/blob/master/public/maintenance.html) is provided, but you can create your own `public/maintenance.html` instead. If you provide a `reason` to the rake task, Turnout will use [Nokogiri](http://nokogiri.org) to parse the `maintenance.html` file and attempt to find a tag with `id="reason"`. It will replace the `inner_html` of the tag with the reason you provided. So be sure your `maintenance.html` file can be parsed as HTML.
|
63
|
+
|
64
|
+
Behind the Scenes
|
65
|
+
=================
|
66
|
+
On every request the Rack app will check to see if `tmp/maintenance.yml` exists. If the file exists the maintenance page will be shown (unless allowed IPs are given and the requester is in the allowed range).
|
67
|
+
|
68
|
+
So if you want to get the maintenance page up or down in a hury `touch tmp/maintenance.yml` and `rm tmp/maintenance.yml` will work.
|
69
|
+
|
70
|
+
Turnout will attempt to parse the `maintenance.yml` file looking for `reason` and `allowed_ip` settings. The file is not cached so you can change these values manually or just rerun the `rake maintenance:start` command.
|
71
|
+
|
72
|
+
Example maintenance.yml File
|
73
|
+
----------------------------
|
74
|
+
|
75
|
+
---
|
76
|
+
reason: Someone told me I should type <code>sudo rm -rf /</code>
|
77
|
+
allowed_paths:
|
78
|
+
- ^/help
|
79
|
+
- ^/contact_us
|
80
|
+
allowed_ips:
|
81
|
+
- 127.0.0.1
|
82
|
+
- 192.168.0.0/24
|
data/lib/rack/turnout.rb
CHANGED
@@ -25,10 +25,18 @@ class Rack::Turnout
|
|
25
25
|
def on?(env)
|
26
26
|
request = Rack::Request.new(env)
|
27
27
|
|
28
|
+
return false if path_allowed?(request.path)
|
28
29
|
return false if ip_allowed?(request.ip)
|
29
30
|
File.exists? settings_file
|
30
31
|
end
|
31
32
|
|
33
|
+
def path_allowed?(path)
|
34
|
+
(settings['allowed_paths'] || []).each do |allowed_path|
|
35
|
+
return true if path =~ Regexp.new(allowed_path)
|
36
|
+
end
|
37
|
+
false
|
38
|
+
end
|
39
|
+
|
32
40
|
def ip_allowed?(ip)
|
33
41
|
ip = IPAddr.new(ip) unless ip.is_a? IPAddr
|
34
42
|
(settings['allowed_ips'] || []).each do |allowed_ip|
|
data/lib/tasks/maintenance.rake
CHANGED
@@ -2,20 +2,42 @@ namespace :maintenance do
|
|
2
2
|
|
3
3
|
desc 'Enable the maintenance mode page ("reason" and/or "allowed_ips" can be passed as environment variables)'
|
4
4
|
task :start do |t, args|
|
5
|
-
settings = {
|
5
|
+
settings = {
|
6
|
+
'reason' => ENV['reason'],
|
7
|
+
'allowed_paths' => split_paths(ENV['allowed_paths']),
|
8
|
+
'allowed_ips' => split_ips(ENV['allowed_ips'])
|
9
|
+
}
|
6
10
|
|
7
11
|
file = File.open settings_file, 'w'
|
8
12
|
file.write settings.to_yaml
|
9
13
|
file.close
|
14
|
+
|
15
|
+
puts "Created #{settings_file}"
|
16
|
+
puts "Run `rake maintenance:end` to stop maintenance mode"
|
10
17
|
end
|
11
18
|
|
12
19
|
desc 'Disable the maintenance mode page'
|
13
20
|
task :end do
|
14
21
|
File.delete settings_file
|
22
|
+
|
23
|
+
puts "Deleted #{settings_file}"
|
15
24
|
end
|
16
25
|
|
17
26
|
def settings_file
|
18
27
|
Rails.root.join('tmp', 'maintenance.yml')
|
19
28
|
end
|
20
29
|
|
30
|
+
def split_paths(paths_string)
|
31
|
+
# used negative lookbehind to split on "," but not on "\,"
|
32
|
+
paths = paths_string.to_s.split(/(?<!\\),\ ?/)
|
33
|
+
paths.map! do |path|
|
34
|
+
path.gsub('\,', ',') # remove the escape characters
|
35
|
+
end
|
36
|
+
paths
|
37
|
+
end
|
38
|
+
|
39
|
+
def split_ips(ips_string)
|
40
|
+
ips_string.to_s.split(',')
|
41
|
+
end
|
42
|
+
|
21
43
|
end
|
data/lib/turnout/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: turnout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-28 00:00:00.000000000 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: nokogiri
|
17
|
-
requirement: &
|
17
|
+
requirement: &71247680 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,7 +22,7 @@ dependencies:
|
|
22
22
|
version: '1.3'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *71247680
|
26
26
|
description: Turnout makes it easy to put your Rails application into maintenance
|
27
27
|
mode
|
28
28
|
email: adam.crownoble@biola.edu
|
@@ -30,6 +30,8 @@ executables: []
|
|
30
30
|
extensions: []
|
31
31
|
extra_rdoc_files: []
|
32
32
|
files:
|
33
|
+
- README.markdown
|
34
|
+
- MIT-LICENSE
|
33
35
|
- lib/turnout.rb
|
34
36
|
- lib/rack/turnout.rb
|
35
37
|
- lib/turnout/version.rb
|