Telling users there is maintenance happening

13 views
Skip to first unread message

Ralph Shnelvar

unread,
Feb 22, 2018, 10:40:47 AM2/22/18
to rubyonra...@googlegroups.com
Rubyonrails-talk friends,

Is there a way to flip a Rails website into a maintenance mode?  That is, have all page requests going to the site go to a "Sorry, we're under maintenance and will be back in 2 hours an 12 minutes."?  And then flip back when maintenance is complete?

I suspect it has something to do with routes.rb but I would love some guidance.

Ralph Shnelvar



Rubyonrails-talk friends,

I'm not sure where to post this question.

I have two computers.  Both have been set up as Rails servers although I only have one of the two machines being a server at any one time because the servers are not serving up static web pages.  My web pages are NOT being hosted by an external ISP.  

Let's call the two machines Server X and Server Y.  Server X is the one that runs as an Apache server for, say 23 hours per day.  Server Y runs WEBrick so I can do development.  Server Y is capable of running Apache.

What I want to do sometimes is shut down Server X and then use Server Y to show an "Under maintenance until X" screen while I do maintenance on Server X.

Since Server X and Server Y are - more or less - identically configured, what is the best way for me to put up an "Under maintenance" web page?

I know there are lots of cute "Under maintenance" web pages "out there."  Is there a preferred one for Rails servers?



As an aside.  Assume Servers X and Y are both running and serving up the same static web pages.  Is there anything wrong with that?

Ralph Shnelvar

Walter Lee Davis

unread,
Feb 22, 2018, 10:51:18 AM2/22/18
to rubyonra...@googlegroups.com
I have used this route in the past to do this in an informal manner:

get '*', redirect_to: '/maintenance.html'

...and put that at or near the top of the routes file. Comment it out when you want to run normally.

The Gem approach will do a more thorough job, catching post and patch and everything.

Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1132452394.20180222083956%40dos32.com.
> For more options, visit https://groups.google.com/d/optout.

Ralph Shnelvar

unread,
Feb 22, 2018, 12:21:24 PM2/22/18
to Ruby on Rails: Talk
So I tried this:

Rails.application.routes.draw do
 
if File.exist?('/home/real-estate-data-mining/MaintenanceNow')

   
get '*', redirect_to: '/maintenance.html'

 
else
    resources
:experiments
    resources
:articles
 
end
end


but it doesn't work

I do see that there is a Rails.application.reload_routes!

So, clearly, I don't understand how routes.rb works.  Is routes building a very expensive process to be done infrequently?

Ralph Shnelvar

Walter Lee Davis

unread,
Feb 22, 2018, 4:57:37 PM2/22/18
to rubyonra...@googlegroups.com
Rails routes are built when the app starts (or if you're under a lot of traffic, if you fork a new Apache process). Rails is a long-running process, and it does not reload at each request. You would have to restart the server to have a change in routes make a difference. If you've deployed with Passenger, then touch tmp/restart.txt will do the trick.

Walter
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c27ea945-c56a-4644-a617-c580f68d32c5%40googlegroups.com.

Rob Jonson

unread,
Feb 24, 2018, 6:03:06 PM2/24/18
to Ruby on Rails: Talk
If you're using capistrano for deployment (it's great!) - then this is a good option


Reply all
Reply to author
Forward
0 new messages