DEV Community

loading...
BoTreeTechnologies

How to put a Ruby on Rails application in Maintenance Mode

Ankur Vyas
Ankur is a Ruby on Rails Developer & Practice Lead JavaScript. He loves Ruby, JavaScript, reading and writing blogs, problem-solving and taking ownership of work.
・2 min read

How to put a Ruby on Rails application in Maintenance Mode

What is the maintenance mode?

Maintenance mode page is the user-friendly message for your site visitors indicating that we are working on something for which the site needs to be down for some time. We require this because we don't want our website to be broken for a specific amount of time while the site maintenance is in progress.

When you hire Ruby on Rails programmers, they can take care of the entire maintenance mode page.

Why you require the maintenance mode page?

  • Performing upgrades (migrate rails version from one to another)
  • Performing data migrations in the backend
  • Migrating images or files from Amazon S3 to Google Cloud or vice versa
  • And many more...

How to so do for Ruby on Rails applications?

The easiest way to do is by using Turnout gem. Turnout is Rack middleware with a Ruby on Rails Development engine that allows you to put your app in maintenance mode easily.

Turnout gem has the following 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

You can find them all of them here.

Installation

Just add the following gem to your Gemfile

gem 'turnout'

and do bundle install that's it!

Activation

$ rake maintenance: start.

Tada! It's done. When you do so, you will get the following page.

Alt Maintenance mode

$ rake maintenance: start reason= "This is the custom reason!"

Alt Custom reason

You can find all the commands here.

Deactivation

$ rake maintenance: end.

Default maintenance pages are provided, but you can create your own public/maintenance.[html|json|html.erb] files instead. Reach out to learn more about the expert web developers in NYC for the various ways to improve or build the quality of projects and across your company.

A Ruby on Rails web development company will ensure that you activate and deactivate maintenance page at the right time.

That's it!

Read Also: Top 3 tips to Boost Performance of your Ruby on Rails Application

Discussion (11)

Collapse
andrewbrown profile image
Andrew Brown 🇨🇦

With modern architecture, Maintenance Mode screens should be a rarity and it wouldn't be the Rails app that would serve it.

So this issue which is an old issue comes from way back when people use to do an in-place deployment, meaning they would deploy on a single server.

Now we have blue/green deployment where you can spin up the entirely new infrastructure you can test that environment out and shift traffic that new version or you can use Canary deployment and shift a portion of your traffic until you determine it's stable and shift 100% of the traffic.

If there was a maintenance page What you'd you do is have a health check on the Load Balancer or DNS level and that would then failover to a static page.

The problem with having a maintenance page in your Rails app is the rails app can be a point of failure which can totally happen when you're upgrading Rails versions or gems.

Now if you want to serve a maintenance page in-place you would be better of changing your Nginx or apache configuration rather than serve a Sinatra app. That's what this gem does which is a bit overkill and itself can be a point of failure for the maintenance page.

Collapse
nhh profile image
Niklas

This is most probably an completely overengineered solution. Good old maintenance pages do their job pretty well. Not all companies are google..

Collapse
nhh profile image
Niklas

Its a tragedy that every company thinks they have to provide a 99,99 Uptime without anyone noticing a maintenance phase. This is so unhealthy and promotes the illusion that maintenance comes at no cost 😩 For the average user a maintenance page is very acceptable..

Thread Thread
andrewbrown profile image
Andrew Brown 🇨🇦

It takes 5 seconds to set up a health check in Route53 on AWS to have it failover to a static page. (maintenance page) You click a couple of buttons and put in an address you want to failover if the target is not healthy.

It takes 3-10 mins to set up that static maintenance page via static website hosting. You could use Github pages or anything you like for this static page.

Blue/Green comes pretty much out of the box with many cloud providers. All of AWS deployment methods makes it dead simple to use Blue/Green to avoid downtime.

In the Rails community even if you wanted to do In-Place we have had Capistrano and Unicorn that it was standard practice to use no-downtime deploy method which is nearly 10 years old.

I would have screenshot all the steps here which took me all of 5 mins to put together but Dev.to image uploads on comments are currently experiencing issues.

This is so unhealthy and promotes the illusion that maintenance comes at no cost

With a little bit of learning, maintenance does come at a reduced cost. Once you know how simple it is, you'll question yourself doing it the old way. Let the old way dies, we are trying to build rockets to mars

Thread Thread
nhh profile image
Niklas

The truth is, not every body rely on aws.

Thread Thread
andrewbrown profile image
Andrew Brown 🇨🇦

And you don't need to use AWS, it has become common functionality among all Cloud Providers and for those who don't want to use one of the big three there are a variety of 3rd party solutions.

The truth is the only reason for not doing is not knowing or old habits.

Thread Thread
nhh profile image
Niklas

I dont think the only reason is knowing or old habits. Some people just explicitly decide against complexity when it is useful. You are generalising about all environments irrespective of the requirements. And beneath aws, azure and google cloud there arent that many providers who sell such advanced features. Even Heroku has this wonderful pragmatic feature „maintenance pages“ so please accept that for some people maintenance pages are useful and a decision rather than the lack of knowledge or old habits...

Thread Thread
andrewbrown profile image
Andrew Brown 🇨🇦 • Edited

Herkou can do both failovers and blue/green and yes you can do maintenance pages for those who don't know yet how easy to use these modern features. It's not complex.

Thread Thread
drbragg profile image
Drew Bragg

I gotta go with Andrew on this one. I use Digital Ocean for my servers and Capistrano to deploy my rails apps. With next to zero config I can deploy an update to any of my apps with zero downtime and if anything was to go wrong with a deployment cap has a built in method to rollback to a previous deployment.

Maybe a maintenance mode could be needed for a different framework but I really can't see anyone needing to put their Rails app into maintenance mode to deploy an update.

Thread Thread
nhh profile image
Niklas

Yeah, Capistrano is great, Zero-Downtime is great and Blue/Green too. Keep using what fits your needs ✌️

Collapse
rsmoke profile image
rsmokeUM

Thank you for this overview of using a maintenance mode. I use them to pause applications during "Off -Season" times for registration or entry submissions. These sort of needs do not require offloading to another server just a public pausing of the current server.