Skip to content
Permalink
Browse files
Merge pull request #747 from london89/alpha
Отслеживание циклов
  • Loading branch information
sergejey committed Jun 1, 2020
2 parents 3cbe926 + b2aadd7 commit 0dd0bbeb1be2fb3db1efc47febe23d7c43efc6b1
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 49 deletions.
@@ -39,6 +39,7 @@
}
}


echo "CONNECTED TO DB" . PHP_EOL;

$old_mask = umask(0);
@@ -131,7 +132,7 @@
if (DB_PASSWORD != '') $mysqlParam .= " -p" . DB_PASSWORD;
$mysqlParam .= " " . DB_NAME . " <" . $db_filename;
exec($mysql_path . $mysqlParam);

if (file_exists($db_history_filename)) {
echo "Running: mysql history db restore from file: " . $db_history_filename . PHP_EOL;
DebMes("Running: mysql history db restore from file: " . $db_history_filename);
@@ -149,8 +150,8 @@

//force check installed data
$source=ROOT.'modules';
if ($dir = @opendir($source)) {
while (($file = readdir($dir)) !== false) {
if ($dir = @opendir($source)) {
while (($file = readdir($dir)) !== false) {
if (Is_Dir($source."/".$file) && ($file!='.') && ($file!='..')) {
@unlink(ROOT."cms/modules_installed/".$file.".installed");
}
@@ -167,6 +168,7 @@
echo "Clearing the cache.\n";
SQLTruncateTable('cached_values');


if (defined('SEPARATE_HISTORY_STORAGE') && SEPARATE_HISTORY_STORAGE==1) {
// split data into multiple tables
$phistory_values = SQLSelect("SELECT VALUE_ID, COUNT(*) as TOTAL FROM phistory GROUP BY VALUE_ID");
@@ -366,26 +368,26 @@
}

}

}

$is_running=array();
foreach($threads->commandLines as $id=>$cmd) {
if (preg_match('/(cycle_.+?)\.php/is',$cmd,$m)) {
$title=$m[1];
$is_running[$title]=$id;
if (!isset($started_when[$title])) $started_when[$title]=time();
if ((time()-$started_when[$title])>30 && !in_array($title,$auto_restarts)) {
DebMes("Adding $title to auto-recovery list",'threads');
$auto_restarts[]=$title;
}
$cycle_updated_timestamp=getGlobal($title.'Run');
if (!$to_start[$title] && $cycle_updated_timestamp && in_array($title,$auto_restarts) && ((time()-$cycle_updated_timestamp)>30*60)) { //
DebMes("Looks like $title is dead. Need to recovery",'threads');
registerError('cycle_hang', $title);
setGlobal($title.'Control','restart');
//$to_stop[$title]=time();
//$to_start[$title]=time()+5;
//
$is_running=array();
foreach($threads->commandLines as $id=>$cmd) {
if (preg_match('/(cycle_.+?)\.php/is',$cmd,$m)) {
$title=$m[1];
$is_running[$title]=$id;
if (!isset($started_when[$title])) $started_when[$title]=time();
if ((time()-$started_when[$title])>30 && !in_array($title,$auto_restarts)) {
DebMes("Adding $title to auto-recovery list",'threads');
$auto_restarts[]=$title;
}
$cycle_updated_timestamp=getGlobal($title.'Run');

if (!$to_start[$title] && $cycle_updated_timestamp && in_array($title,$auto_restarts) && ((time()-$cycle_updated_timestamp)>30*60)) { //
DebMes("Looks like $title is dead. Need to recovery",'threads');
registerError('cycle_hang', $title);
setGlobal($title.'Control','restart');
//$to_stop[$title]=time();
//$to_start[$title]=time()+5;
}
}
}
}
@@ -138,11 +138,7 @@ public function Connect()
else
{
$this->latestTransaction=time();
mysql_query("SET NAMES 'utf8';", $this->dbh);
mysql_query("SET CHARACTER SET 'utf8';", $this->dbh);
mysql_query("set character_set_client='utf8';", $this->dbh);
mysql_query("set character_set_results='utf8';", $this->dbh);
mysql_query("set collation_connection='utf8_general_ci';", $this->dbh);
mysql_query("set NAMES 'utf8', CHARACTER SET 'utf8', character_set_client='utf8', character_set_results='utf8', collation_connection='utf8_general_ci';");

return 1;
}
@@ -160,11 +160,7 @@ public function Connect()
} else
{
$this->latestTransaction=time();
$this->Exec("SET NAMES 'utf8';");
$this->Exec("SET CHARACTER SET 'utf8';");
$this->Exec("set character_set_client='utf8';");
$this->Exec("set character_set_results='utf8';");
$this->Exec("set collation_connection='utf8_general_ci';");
$this->Exec("set NAMES 'utf8', CHARACTER SET 'utf8', character_set_client='utf8', character_set_results='utf8', collation_connection='utf8_general_ci';");
return 1;
}

@@ -69,7 +69,9 @@ private function cycleAlive()
$this->_latestAlive = time();
global $cycleName;
if ($cycleName) {
setGlobal($cycleName, time(), 1);
// setGlobal($cycleName, time(), 1);
$checked_time = time();
saveToCache('MJD:ThisComputer'.$cycleName, $checked_time);
$ws_clients_total = count($this->_clients);
$old_value = gg('WSClientsTotal');
if ($ws_clients_total != $old_value) {
@@ -29,6 +29,9 @@

const CONNECT_HOST = 'connect.smartliving.ru';

setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

while (1) {
$connect = new connect();
$connect->getConfig();
@@ -87,7 +90,9 @@
$currentMillis = round(microtime(true) * 10000);
if ($currentMillis - $previousMillis > 10000) {
$previousMillis = $currentMillis;
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
$checked_time=time();
//setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
saveToCache("MJD:$cycleVarName", $checked_time);
if (file_exists('./reboot') || IsSet($_GET['onetime'])) {
exit;
}
@@ -233,4 +238,3 @@ function update_menu_data($element_id = 0)
//echo "Items not changed\n";
}
}

@@ -13,14 +13,16 @@

$ctl = new control_modules();
$checked_time = 0;
setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

echo date("H:i:s") . " running " . basename(__FILE__) . "\n";
SQLExec("DELETE FROM safe_execs");

while (1) {
if (time() - $checked_time > 20) {
$checked_time = time();
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
saveToCache("MJD:$cycleVarName", $checked_time);
}

if ($exclusive = SQLSelectOne("SELECT * FROM safe_execs WHERE EXCLUSIVE = 1 ORDER BY PRIORITY DESC, ID")) {
@@ -13,7 +13,8 @@

$ctl = new control_modules();

setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

echo "Running startup maintenance" . PHP_EOL;
$run_from_start = 1;
@@ -56,7 +57,8 @@
while (1) {
if (time() - $checked_time > 5) {
$checked_time = time();
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
// setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
saveToCache("MJD:$cycleVarName", $checked_time);

$timestamp = time() - getGlobal('ThisComputer.started_time');
setGlobal('ThisComputer.uptime', $timestamp);
@@ -25,14 +25,18 @@
}

$checked_time = 0;
setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

echo date("H:i:s") . " running " . basename(__FILE__) . "\n";

$processed = array();

while (1) {
if (time() - $checked_time > 5) {
$checked_time = time();
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
// setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
saveToCache("MJD:$cycleVarName", $checked_time);
}


@@ -59,7 +63,7 @@

$tmp=SQLSelectOne("SELECT COUNT(*) as TOTAL FROM phistory_queue;");
$count_queue = (int)$tmp['TOTAL'];

$queue = SQLSelect("SELECT * FROM phistory_queue ORDER BY ID LIMIT ". $limit);
if ($queue[0]['ID']) {
if ($count_queue>$limit && !$queue_error_status) {
@@ -18,6 +18,8 @@
$pinghosts = new pinghosts();

$checked_time = 0;
setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

echo date("H:i:s") . " running " . basename(__FILE__) . PHP_EOL;

@@ -26,8 +28,8 @@
if (time() - $checked_time > 10)
{
$checked_time = time();
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);

//setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
saveToCache("MJD:$cycleVarName", $checked_time);
// checking all hosts
$pinghosts->checkAllHosts();
}
@@ -17,12 +17,16 @@
$sc = new scripts();
$checked_time = 0;

setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

echo date("H:i:s") . " running " . basename(__FILE__) . PHP_EOL;

while (1) {
if ((time()-$checked_time)>5) {
$checked_time = time();
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
//setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
saveToCache("MJD:$cycleVarName", $checked_time);
}
runScheduledJobs();
$sc->checkScheduledScripts();
@@ -15,6 +15,9 @@

$checked_time = 0;

setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

$objects = getObjectsByClass('systemStates');
$total = count($objects);

@@ -25,7 +28,6 @@
if ((time() - $last_run) > 5 * 60)
{
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);

for ($i = 0; $i < $total; $i++)
{
callMethod($objects[$i]['TITLE'] . '.checkState');
@@ -40,10 +42,12 @@

while (1)
{
if (time() - $checked_time > 5)
if (time() - $checked_time > 10)
{
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
//setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
$checked_time = time();
saveToCache("MJD:$cycleVarName", $checked_time);

for ($i = 0; $i < $total; $i++)
{
callMethod($objects[$i]['TITLE'] . '.checkState');
@@ -18,6 +18,9 @@
echo date("H:i:s") . " running " . basename(__FILE__) . PHP_EOL;

$latest_sent=time();
setGlobal((str_replace('.php', '', basename(__FILE__))).'Run', time(), 1);
$cycleVarName='ThisComputer.'.str_replace('.php', '', basename(__FILE__)).'Run';

clearTimeout('restartWebSocket');

while (1)
@@ -55,10 +58,12 @@
$sent_ok=0;
}
}

if ($sent_ok) {
$latest_sent=time();
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', $latest_sent, 1);
saveToCache("MJD:$cycleVarName", $latest_sent);

//setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', $latest_sent, 1);
setTimeout('restartWebSocket','sg("cycle_websocketsRun","");sg("cycle_websocketsControl","restart");',5*60); //registerError("websockets","Error posting to websocket daemon.");
} else {
echo date("H:i:s") . ' Error while posting to websocket.'."\n";

0 comments on commit 0dd0bbe

Please sign in to comment.