Rails: Display Maintenance Page if No Database Connection Available

Posted by RobB on Stack Overflow See other posts from Stack Overflow or by RobB
Published on 2010-05-26T18:49:01Z Indexed on 2010/05/27 1:21 UTC
Read the original article Hit count: 295

Filed under:
|
|
|

I'm looking for a solution that will allow my rails app to render a user-friendly maintenance page when there is no Mysql server available to connect to.

Normally a Mysql::Error is thrown from the mysql connection adapter in active_record. Something like: /!\ FAILSAFE /!\ Wed May 26 11:40:14 -0700 2010 Status: 500 Internal Server Error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

Is there a low-overhead way to catch this error and render a maintenance page instead?

I'm assuming that since connections are actually made in the active_record mysql adapter the app never makes it to the controller stack before it throws the error, so you can't catch it in a controller.

Any input would be greatly appreciated.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about ruby-on-rails