<commit_before>Turnout [![Build Status](https://travis-ci.org/biola/turnout.png?branch=master)](https://travis-ci.org/biola/turnout) [![Code Climate](https://codeclimate.com/github/biola/turnout.png)](https://codeclimate.com/github/biola/turnout)
=======
Turnout is [Rack](http://rack.rubyforge.org/) middleware with a [Ruby on Rails](http://rubyonrails.org) engine that allows you to easily put your app in maintenance mode.

Features
========
* Easy installation
* Rake commands to turn maintenance mode on and off
* Easily provide a reason for each downtime without editing the maintenance.html file
* Allow certain IPs or IP ranges to bypass the maintenance page
* Allow certain paths to be accessible during maintenance
* Easily override the default maintenance.html file with your own
* Simple [YAML](http://yaml.org) based config file for easy activation, deactivation and configuration without the rake commands
* Support for multiple maintenance page formats. Current [HTML](http://en.wikipedia.org/wiki/HTML) and [JSON](http://en.wikipedia.org/wiki/JSON)
* Supports Rails, [Sinatra](http://sinatrarb.com) and any other Rack application
* Supports multiple maintenance file paths so that groups of applications can be put into maintenance mode at once.

Installation
============
Rails 3+
--------
In your `Gemfile` add:

    gem 'turnout'

then run

    bundle install

Sinatra
-------

In your Sinatra app file

```ruby
require 'rack/turnout'

class App < Sinatra::Base
  configure do
    use Rack::Turnout
```

In your Rakefile

```ruby
require 'turnout/rake_tasks'
```

Activation
==========

    rake maintenance:start

or

    rake maintenance:start reason="Somebody googled Google!"

or

    rake maintenance:start allowed_paths="/login,^/faqs/[0-9]*"

or

    rake maintenance:start allowed_ips="4.8.15.16"

or

    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"
    
or if you've configured `named_maintenance_file_paths` with a path named `server`

    rake maintenance:server:start

Notes
-----
* The `reason` parameter can contain HTML
* Multiple `allowed_paths` and `allowed_ips` can be given. Just comma separate them.
* All `allowed_paths` are treated as regular expressions.
* If you need to use a comma in an `allowed_paths` regular expression just escape it with a backslash: `\,`.
* IP ranges can be given to `allowed_ips` using [CIDR notation](http://en.wikipedia.org/wiki/CIDR_notation).

Deactivation
============

    rake maintenance:end

or if you activated with a named path like `server`

    rake maintenance:server:end

Configuration
=============

Turnout can be configured in two different ways:

1. __Pass a config hash to the middleware__

    ```ruby
    use Rack::Turnout,
      app_root: '/some/path',
      named_maintenance_file_paths: {app: 'tmp/app.yml', server: '/tmp/server.yml'},
      default_mainteance_page: Turnout::MaintenancePage::JSON,
      default_reason: 'Somebody googled Google!',
      default_response_code: 418
    ```

2. __Using a config block__

    ```ruby
    Turnout.configure do |config|
      config.app_root = '/some/path'
      config.named_maintenance_file_paths = {app: 'tmp/app.yml', server: '/tmp/server.yml'},
      config.default_maintenance_page = Turnout::MaintenancePage::JSON
      config.default_reason = 'Somebody googled Google!'
      config.default_response_code = 418
    end
    ```

__NOTICE:__ Any custom configuration should be loaded not only in the app but in the rake task. This should happen automatically in Rails as the `environment` task is run if it exists. But you may want to create your own `environment` task in non-Rails apps.

Default Configuration
---------------------

```ruby
Turnout.configure do |config|
  config.app_root = '.',
  config.named_maintenance_file_paths = {default: app_root.join('tmp', 'maintenance.yml').to_s},
  config.default_maintenance_page = Turnout::MaintenancePage::HTML,
  config.default_reason = "The site is temporarily down for maintenance.\nPlease check back soon.",
  config.default_response_code = 503
end
}<commit_msg>Remove stray }<commit_after>Turnout [![Build Status](https://travis-ci.org/biola/turnout.png?branch=master)](https://travis-ci.org/biola/turnout) [![Code Climate](https://codeclimate.com/github/biola/turnout.png)](https://codeclimate.com/github/biola/turnout)
=======
Turnout is [Rack](http://rack.rubyforge.org/) middleware with a [Ruby on Rails](http://rubyonrails.org) engine that allows you to easily put your app in maintenance mode.

Features
========
* Easy installation
* Rake commands to turn maintenance mode on and off
* Easily provide a reason for each downtime without editing the maintenance.html file
* Allow certain IPs or IP ranges to bypass the maintenance page
* Allow certain paths to be accessible during maintenance
* Easily override the default maintenance.html file with your own
* Simple [YAML](http://yaml.org) based config file for easy activation, deactivation and configuration without the rake commands
* Support for multiple maintenance page formats. Current [HTML](http://en.wikipedia.org/wiki/HTML) and [JSON](http://en.wikipedia.org/wiki/JSON)
* Supports Rails, [Sinatra](http://sinatrarb.com) and any other Rack application
* Supports multiple maintenance file paths so that groups of applications can be put into maintenance mode at once.

Installation
============
Rails 3+
--------
In your `Gemfile` add:

    gem 'turnout'

then run

    bundle install

Sinatra
-------

In your Sinatra app file

```ruby
require 'rack/turnout'

class App < Sinatra::Base
  configure do
    use Rack::Turnout
```

In your Rakefile

```ruby
require 'turnout/rake_tasks'
```

Activation
==========

    rake maintenance:start

or

    rake maintenance:start reason="Somebody googled Google!"

or

    rake maintenance:start allowed_paths="/login,^/faqs/[0-9]*"

or

    rake maintenance:start allowed_ips="172.16.31.10"

or

    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"
    
or if you've configured `named_maintenance_file_paths` with a path named `server`

    rake maintenance:server:start

Notes
-----
* The `reason` parameter can contain HTML
* Multiple `allowed_paths` and `allowed_ips` can be given. Just comma separate them.
* All `allowed_paths` are treated as regular expressions.
* If you need to use a comma in an `allowed_paths` regular expression just escape it with a backslash: `\,`.
* IP ranges can be given to `allowed_ips` using [CIDR notation](http://en.wikipedia.org/wiki/CIDR_notation).

Deactivation
============

    rake maintenance:end

or if you activated with a named path like `server`

    rake maintenance:server:end

Configuration
=============

Turnout can be configured in two different ways:

1. __Pass a config hash to the middleware__

    ```ruby
    use Rack::Turnout,
      app_root: '/some/path',
      named_maintenance_file_paths: {app: 'tmp/app.yml', server: '/tmp/server.yml'},
      default_mainteance_page: Turnout::MaintenancePage::JSON,
      default_reason: 'Somebody googled Google!',
      default_response_code: 418
    ```

2. __Using a config block__

    ```ruby
    Turnout.configure do |config|
      config.app_root = '/some/path'
      config.named_maintenance_file_paths = {app: 'tmp/app.yml', server: '/tmp/server.yml'},
      config.default_maintenance_page = Turnout::MaintenancePage::JSON
      config.default_reason = 'Somebody googled Google!'
      config.default_response_code = 418
    end
    ```

__NOTICE:__ Any custom configuration should be loaded not only in the app but in the rake task. This should happen automatically in Rails as the `environment` task is run if it exists. But you may want to create your own `environment` task in non-Rails apps.

Default Configuration
---------------------

```ruby
Turnout.configure do |config|
  config.app_root = '.',
  config.named_maintenance_file_paths = {default: app_root.join('tmp', 'maintenance.yml').to_s},
  config.default_maintenance_page = Turnout::MaintenancePage::HTML,
  config.default_reason = "The site is temporarily down for maintenance.\nPlease check back soon.",
  config.default_response_code = 503
end
{'fraction_non_alphanumeric': 0.12192206550322734, 'fraction_numerical': 0.008964857757590245, 'mean_word_length': 4.19044665012407, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4240482', 'n_tokens_mistral': 2575, 'n_tokens_neox': 2393, 'n_words': 818}