2

We have Cloudflare sitting in front of our Drupal sites - and in order to take advantage of their "AlwaysOnline" feature - we need to alter the response code sent in the event of an error.

I want to cater for when the database is unavailable - as this can sometimes happen when upgrading the MySQL server.

The only way I've found so far is to hack the errors.inc file:

if ($fatal) {
    drupal_add_http_header('Status', '504 Service unavailable (with message)');
  }

Is there a more elegant way to achieve what I'm after?

2

You could use a template_preprocess_maintenance_page() invocation in your theme's template.php so that when you go to maintenance mode (or the DB is down) it will trigger your needed status code:

function MYTHEME_preprocess_maintenance_page(&$variables) {
  drupal_add_http_header('Status', '504 Service unavailable (with message)');
}
  • This works great for the regular maintenance page - but when the Database is down - in order for the theme hook to fire, I set this in my settings: $conf['maintenance_theme'] = 'zurb_neway'; This in turn then calls system_list() to get all modules... so the page never renders? – Wayne Foster May 20 '16 at 9:26
  • I got this working by adding your code to a simpler theme in /sites/all/themes/bartik - this now works across all my multi-site install - so great work! – Wayne Foster May 20 '16 at 10:01

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.