Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
clear_cron_deadlock.php
1 <?php
25 error_reporting(E_ALL);
26 
32 function printHelp()
33 {
34  print "Usage: clearCronDeadlock.php SYSTEM_ROOT [--reset] [--force]\r\n\r\n";
35 };
36 
37 if ((php_sapi_name() != 'cli')) trigger_error("You can only run this script from the command line\n", E_USER_ERROR);
38 $SYSTEM_ROOT = (isset($_SERVER['argv'][1])) ? $_SERVER['argv'][1] : '';
39 if (empty($SYSTEM_ROOT)) {
40  echo "ERROR: You need to supply the path to the System Root as the first argument\n";
41  printHelp();
42  exit();
43 }
44 
45 if (!is_dir($SYSTEM_ROOT) || !is_readable($SYSTEM_ROOT.'/core/include/init.inc')) {
46  echo "ERROR: Path provided doesn't point to a Matrix installation's System Root. Please provide correct path and try again.\n";
47  printHelp();
48  exit();
49 }
50 
51 $RESET = (isset($_SERVER['argv'][2]) && $_SERVER['argv'][2] == '--reset') ? true : false;
52 $FORCE = (isset($_SERVER['argv'][3]) && $_SERVER['argv'][3] == '--force') ? true : false;
53 
54 require_once $SYSTEM_ROOT.'/core/include/init.inc';
55 
56 $root_user=&$GLOBALS['SQ_SYSTEM']->am->getSystemAsset('root_user');
57 if (!$GLOBALS['SQ_SYSTEM']->setCurrentUser($root_user)) {
58  echo "ERROR: Failed login in as root user\n";
59  exit();
60 }
61 
62 $cronManager=&$GLOBALS['SQ_SYSTEM']->am->getSystemAsset('cron_manager');
63 $cronRunning=$cronManager->attr('running');
64 $cronRunCheck=(int)$cronManager->attr('run_check');
65 $cronWarnLimit=(int)$cronManager->attr('warn_after_num_run_checks');
66 $cr=($cronRunning) ? 'Yes' : 'No';
67 
68 print 'Cron Running: ' . $cr . ', Run Checks: ' . $cronRunCheck . '/' . $cronWarnLimit . "\r\n";
69 if ($RESET) {
70  if (($cronRunning && $cronRunCheck >= $cronWarnLimit) || $FORCE) {
71  $GLOBALS['SQ_SYSTEM']->am->acquireLock($cronManager->id,'attributes');
72  $cronManager->setAttrValue('running', FALSE);
73  $cronManager->setAttrValue('run_check', 0);
74  $cronManager->saveAttributes();
75  $GLOBALS['SQ_SYSTEM']->am->releaseLock($cronManager->id,'attributes');
76  if ($FORCE) {
77  echo "Manual Reset Complete\r\n";
78  } else {
79  echo "Deadlock Cleared\r\n";
80  };
81  } else {
82  echo "No Deadlock Detected\r\n";
83  };
84 } else {
85  if ($cronRunning && $cronRunCheck >= $cronWarnLimit) {
86  echo "Deadlock Detected\r\n";
87  } else {
88  echo "No Deadlock Detected, To force manual reset use --reset --force\r\n";
89  };
90 };
91 ?>