Advertisement
Guest User

Drupal 7 varnish status file

a guest
Mar 12th, 2012
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. <?php
  2. // Register our shutdown function so that no other shutdown functions run before this one.
  3. // This shutdown function calls exit(), immediately short-circuiting any other shutdown functions,
  4. // such as those registered by the devel.module for statistics.
  5. define('DRUPAL_ROOT', getcwd());
  6. register_shutdown_function('status_shutdown');
  7. function status_shutdown() {
  8.   exit();
  9. }
  10.  
  11. // Drupal bootstrap.
  12. require_once './includes/bootstrap.inc';
  13. drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  14.  
  15. // Build up our list of errors.
  16. $errors = array();
  17.  
  18. // Check that the main database is active.
  19. $account = db_select('users','u')
  20.         ->fields('u')
  21.         ->condition('uid',1,'=')
  22.         ->execute()
  23.         ->fetchObject();
  24.  
  25. if ($account->uid != 1) {
  26.   $errors[] = 'Master database not responding.';
  27. }
  28.  
  29. // Check that the website is online
  30. $mode_obj = db_select('variable', 'v')->fields('v')->condition('name', "maintenance_mode", "=")->execute()->fetchObject();
  31. if($mode_obj->value)
  32. {
  33.   $mode = unserialize($mode_obj->value);
  34.   if ($mode != 0) {
  35.     $errors[] = 'Site offline';
  36.   }
  37. }
  38. else
  39. {
  40.   $errors[] = 'Could not fetch the offline status of the website.';
  41. }
  42.  
  43. // Check that the files directory is operating properly. Do not use variable_get, not initialized yet.
  44. $files_path_obj = db_select('variable', 'v')->fields('v')->condition('name', "file_public_path", "=")->execute()->fetchObject();
  45. if($files_path_obj->value)
  46.   $files_path = unserialize($files_path_obj->value);
  47. if ($files_path && $test = tempnam($files_path, 'status_check_')) {
  48.   if (!unlink($test)) {
  49.     $errors[] = 'Could not delete newly created file in the files directory.';
  50.   }
  51. }
  52. else {
  53.   $errors[] = 'Could not create a file in the files directory.';
  54. }
  55.  
  56. // Print all errors.
  57. if (count($errors) > 0) {
  58.   header('HTTP/1.1 500 Internal Server Error');
  59.   print 'NOK' . ' 500' . '<br />';
  60.   print implode("<br />\n", $errors);
  61. }
  62. else {
  63.   // Split up this message, to prevent the remote chance of monitoring software
  64.   // reading the source code if mod_php fails and then matching the string.
  65.   print 'OK' . ' 200';
  66. }
  67.  
  68. // Exit immediately, note the shutdown function registered at the top of the file.
  69. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement