Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top