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?

1 Answer 1

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)');
}
2
  • 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? May 20, 2016 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! May 20, 2016 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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