Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.339
diff -u -p -r1.339 bootstrap.inc
--- includes/bootstrap.inc	3 Jan 2010 01:23:49 -0000	1.339
+++ includes/bootstrap.inc	4 Jan 2010 16:33:19 -0000
@@ -716,18 +716,27 @@ function drupal_get_filename($type, $nam
  */
 function variable_initialize($conf = array()) {
   // NOTE: caching the variables improves performance by 20% when serving cached pages.
-  if ($cached = cache_get('variables', 'cache_bootstrap')) {
-    $variables = $cached->data;
+  $variables = array();
+  try {
+    if ($cached = cache_get('variables', 'cache_bootstrap')) {
+      $variables = $cached->data;
+    }
+    else {
+      $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
+      cache_set('variables', $variables, 'cache_bootstrap');
+    }
+
+    foreach ($conf as $name => $value) {
+      $variables[$name] = $value;
+    }
   }
-  else {
-    $variables = array_map('unserialize', db_query('SELECT name, value FROM {variable}')->fetchAllKeyed());
-    cache_set('variables', $variables, 'cache_bootstrap');
+  catch (Exception $e) {
+    // Do nothing.
   }
 
-  foreach ($conf as $name => $value) {
-    $variables[$name] = $value;
+  if (!isset($variables['install_time']) && !(defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'install')) {
+    drupal_service_unavailable('unable to initialize variables');
   }
-
   return $variables;
 }
 
@@ -2284,3 +2293,21 @@ function drupal_is_cli() {
 function drupal_placeholder($variables) {
   return '<em class="placeholder">' . check_plain($variables['text']) . '</em>';
 }
+
+/**
+ * Handle unavailablity of service before maintenance theme is possible and database might not be available
+ *
+ * @param $guru_meditation
+ *   Message to be displayed so that a user could inform site administrator with a helpful message
+ */
+function drupal_service_unavailable($guru_meditation = NULL) {
+  header($_SERVER['SERVER_PROTOCOL'] . ' 503 Service Temporarily Unavailable');
+  header('Retry-After: 3600');
+
+  print '<h1>Service Temporarily Unavailable</h1>';
+  print '<p>The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.</p>'; 
+  if (isset($guru_meditation)) {
+    print '<p><strong>Guru meditation:</strong> '. $guru_meditation .'</p>';
+  }
+  exit();
+}
\ No newline at end of file
