I'm trying to handle a planned database outage and want Drupal to show the maintenance page during that time.

  • $conf['maintenance_theme'] = 'exampletheme' and a suitable $conf['_message'] are set in my sites/sitename.com/settings.php
  • I have a maintenace-page--offline.tpl.php and maintenance-page.tpl.php in sites/all/themes/exampletheme/templates/
  • I set $conf['maintenance_mode'] = TRUE in sites/sitename.com/settings.php

I hope that Drupal that does not have a database can still bootstrap and display the contents of maintenance-page--offline-tpl.php in this configuration, but in my testing it seems that's not the case. Should this work? Anything I should look into?

  • @brotherperes I've read through that now and followed the instructions and it seems it's not working. So, I guess this question is asking for help to understand why this feature is not working for me. – greggles Feb 5 '18 at 23:18
  • Well there is one way to find out, Are you thinking what I'm thinking? – No Sssweat Feb 6 '18 at 6:24
  • yes. Clone the website to a different location first. I've got the process to do that if you need. – Tiago Martins Peres 李大仁 Feb 6 '18 at 10:58
  • I'd say no you'd need a database working as the variable that defines if the site is/isn't in maintenance mode is itself stored in the database. A dirty but quick workaround would be to temporary hack the index.php and do a print 'Site in maintenance mode'; die; or something similar – Leigh Feb 6 '18 at 14:42

What you're describing should work: the maintenance-page--offline.tpl.php template should be called when the database is unavailable.

Drupal does not bootstrap completely when there is no database, but does so partially. When the bootstrap process fails to contact the database, it calls _drupal_log_error() in include/errors.inc, which (indirectly) calls _drupal_maintenance_theme() in includes/theme.maintenance.inc. This is enough to allow hook invocations to work, and to load the theme specified in your $conf['maintenance_theme'] setting.

First, I would verify that _drupal_maintenance_theme() is being called and that it's finding your theme. If you're using a debugger, set a breakpoint there. If not, add this line at the end of the function:

  echo "<p>Custom theme: $custom_theme</p>";

If all is ok up to this point, try starting off with the simplest possible maintenance page in maintenance-page--offline.tpl.php, e.g.

<h1>Hello world</h1>

If that works, and your maintenance page does not, perhaps your maintenance page contains something that attempts to access the database, or invokes a hook that attempts to access the database? Can you post your template and any errors you are seeing?

If the simple maintenance page doesn't work, more debugging would be needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.