Advertisement
Guest User

Drupal 6 varnish status file

a guest
Mar 12th, 2012
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.08 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. register_shutdown_function('status_shutdown');
  6. function status_shutdown() {
  7.   exit();
  8. }
  9.  
  10. // Drupal bootstrap.
  11. require_once './includes/bootstrap.inc';
  12. drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
  13.  
  14. // Build up our list of errors.
  15. $errors = array();
  16.  
  17. // Check that the main database is active.
  18. $result = db_query('SELECT * FROM {users} WHERE uid = 1');
  19. $account = db_fetch_object($result);
  20. if ($account->uid != 1) {
  21.   $errors[] = 'Master database not responding.';
  22. }
  23.  
  24. // Check that the website is online
  25. $result = db_query('SELECT * FROM {variable} where name = "site_offline"');
  26. $mode_obj = db_fetch_object($result);
  27. if($mode_obj->value)
  28. {
  29.   $mode = unserialize($mode_obj->value);
  30.   if ($mode != 0) {
  31.     $errors[] = 'Site offline';
  32.   }
  33. }
  34. else
  35. {
  36.   $errors[] = 'Could not fetch the offline status of the website.';
  37. }
  38.  
  39. // Check that the files directory is operating properly. Do not use variable_get, not initialized yet.
  40. $files_path_obj = db_fetch_object(db_query('SELECT * FROM {variable} WHERE name = "file_directory_path"'));
  41. if($files_path_obj->value)
  42.   $files_path = unserialize($files_path_obj->value);
  43. if ($files_path && $test = tempnam($files_path, 'status_check_')) {
  44.   if (!unlink($test)) {
  45.     $errors[] = 'Could not delete newly created file in the files directory.';
  46.   }
  47. }
  48. else {
  49.   $errors[] = 'Could not create a file in the files directory.';
  50. }
  51.  
  52. // Print all errors.
  53. if (count($errors) > 0) {
  54.   header('HTTP/1.1 500 Internal Server Error');
  55.   print 'NOK' . ' 500' . '<br />';
  56.   print implode("<br />\n", $errors);
  57. }
  58. else {
  59.   // Split up this message, to prevent the remote chance of monitoring software
  60.   // reading the source code if mod_php fails and then matching the string.
  61.   print 'OK' . ' 200';
  62. }
  63.  
  64. // Exit immediately, note the shutdown function registered at the top of the file.
  65. exit();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement