Ruby / Rails displays a common screen when changes are made on the server

I have a ruby ​​on rails application that runs a server, and sometimes it needs to be uninstalled for / etc updates. At the moment, one way to see the common screen during updates (when the application does not work) is to replace the files in the / srv / www / directory so that it displays the common screen wherever the user could go to. I also thought about the file a central controller that connects all the others (essentially the main ones), but this seems to be intuitive for rails.

There are many external links to these different components of the site that the user can move from the outside, and I need to make sure that they always get this general update screen when the application is slightly reduced.

I was wondering if anyone has any other ideas ... maybe a library or something like that, I can not find anything on the Internet. Any suggestions would be appreciated.

thank

+3
source share
3 answers

I use this Capistrano task:

namespace :deploy do
  namespace :web do
    desc <<-DESC
      Present a maintenance page to visitors. Disables your application web \
      interface by writing a "maintenance.html" file to each web server. The \
      servers must be configured to detect the presence of this file, and if \
      it is present, always display it instead of performing the request.

      By default, the maintenance page will just say the site is down for \
      "maintenance", and will be back "shortly", but you can customize the \
      page by specifying the REASON and UNTIL environment variables:

        $ cap deploy:web:disable \\
              REASON="a hardware upgrade" \\
              UNTIL="12pm Central Time"

      Further customization will require that you write your own task.
    DESC
    task :disable, :roles => :web do
      require 'erb'
      on_rollback { run "rm #{shared_path}/system/maintenance.html" }

      reason = ENV['REASON']
      deadline = ENV['UNTIL']      
      template = File.read('app/views/admin/maintenance.html.erb')
      page = ERB.new(template).result(binding)

      put page, "#{shared_path}/system/maintenance.html", :mode => 0644
    end
  end
end

The file app/views/admin/maintenance.html.erbshould contain:

<p>We’re currently offline for <%= reason ? reason : 'maintenance' %> as of <%= Time.now.utc.strftime('%H:%M %Z') %>.</p>
<p>Sorry for the inconvenience. We’ll be back <%= deadline ? "by #{deadline}" : 'shortly' %>.</p>

The last step is to configure the Apache virtual host with some directives to search for the file maintenance.htmland redirect all requests to it if it is present:

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Redirect all requests to the maintenance page if present
  RewriteCond %{REQUEST_URI} !\.(css|gif|jpg|png)$
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]
</IfModule>

To enable the application in maintenance mode, start cap deploy:web:disableand restart it cap deploy:web:enable.

0
source

- (nginx apache) maintenance.html 503, . , URL , .html , .

,

+3

Capistrano has tons of built-in recipes for displaying service pages and is fully integrated with git / subversion. Makes deployment and management easy.

0
source

Source: https://habr.com/ru/post/1736071/


All Articles