Need to alter response headers for error pages
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(&amp;$variables) {
  drupal_add_http_header('Status', '504 Service unavailable (with message)');
}