} } $childpid = posix_getpid(); @file_put_contents($GLOBALS["EXEC_PID_FILE"], $childpid); FillMemory(); $renice_bin = $GLOBALS["CLASS_UNIX"]->find_program("renice"); events("{$renice_bin} 19 {$childpid}", __FUNCTION__, __LINE__); shell_exec('export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11 &'); shell_exec("{$renice_bin} 19 {$childpid} &"); events("Started pid {$childpid}", __FUNCTION__, __LINE__); while ($stop_server == false) { sleep(10); if ($reload) { $reload = false; events("reload daemon", __FUNCTION__, __LINE__); FillMemory(); } } function sig_handler($signo) { global $stop_server; global $reload; switch ($signo) { case SIGTERM: $stop_server = true; break; case 1: $reload = true; default: if ($signo != 17) { events("Receive sig_handler {$signo}", __FUNCTION__, __LINE__);
function launch_all_status() { $functions = array("group5", "group10", "group30s", "group10s", "group0", "group2", "group300", "group120", "group30", "group60mn", "group5h", "group24h", "watchdog_artica_status"); $system_is_overloaded = system_is_overloaded(); $systemMaxOverloaded = systemMaxOverloaded(); FillMemory(); while (list($num, $func) = each($functions)) { if ($system_is_overloaded) { events("System is overloaded: ({$GLOBALS["SYSTEM_INTERNAL_LOAD"]}}, pause 10 seconds", __FUNCTION__, __LINE__); sleep(10); continue; } else { if ($systemMaxOverloaded) { events("System is very overloaded, pause stop", __FUNCTION__, __LINE__); return; continue; } } usleep(10000); call_user_func($func); } $already = array(); $AlreadyTests = array(); if (count($GLOBALS["CMDS"]) > 0) { events("scheduling " . count($GLOBALS["CMDS"]) . " commands", __FUNCTION__, __LINE__); $FileDataCommand = @file_get_contents('/etc/artica-postfix/background'); $tbl = explode("\n", $FileDataCommand); while (list($num, $zcommands) = each($GLOBALS["CMDS"])) { if (trim($zcommands) == null) { continue; } if (preg_match("#^(.+?)\\s+#", $zcommands, $re)) { if (!$AlreadyTests[$fileTests]) { $fileTests = trim("{$re[1]}"); if (!is_file($fileTests)) { events("running {$fileTests} No such file", __FUNCTION__, __LINE__); continue; } else { $AlreadyTests[$fileTests] = true; } } } if (!$already[$zcommands]) { $tbl[] = $zcommands; $already[$zcommands] = true; } } @file_put_contents('/etc/artica-postfix/background', implode("\n", $tbl)); unset($GLOBALS["CMDS"]); $mem = round(memory_get_usage() / 1024 / 1000, 2); events("{$mem}MB consumed in memory", __FUNCTION__, __LINE__); if ($GLOBALS["TOTAL_MEMORY_MB"] < 400) { $unix = new unix(); $cmd = trim($nohup . " {$GLOBALS["EXEC_NICE"]}" . $unix->LOCATE_PHP5_BIN() . " " . dirname(__FILE__) . "/exec.parse-orders.php >/dev/null 2>&1 &"); shell_exec($cmd); } } @file_put_contents("/etc/artica-postfix/pids/" . basename(__FILE__) . ".GLOBALS", serialize($GLOBALS["TIME"])); }
function launch_all_status() { $functions = array("group5", "group10", "group30s", "group10s", "group0", "group2", "group300", "group120", "group30", "group60mn", "group5h", "group24h", "watchdog_artica_status"); $system_is_overloaded = system_is_overloaded(); $systemMaxOverloaded = systemMaxOverloaded(); FillMemory(); while (list($num, $func) = each($functions)) { if ($system_is_overloaded) { events("System is overloaded: ({$GLOBALS["SYSTEM_INTERNAL_LOAD"]}}, pause 10 seconds", __FUNCTION__, __LINE__); sleep(10); continue; } else { if ($systemMaxOverloaded) { events("System is very overloaded, pause stop", __FUNCTION__, __LINE__); return; continue; } } sleep(1); call_user_func($func); } $already = array(); $AlreadyTests = array(); if (count($GLOBALS["CMDS"]) > 0) { events("scheduling " . count($GLOBALS["CMDS"]) . " commands", __FUNCTION__, __LINE__); $FileDataCommand = @file_get_contents('/etc/artica-postfix/background'); $tbl = explode("\n", $FileDataCommand); while (list($num, $zcommands) = each($GLOBALS["CMDS"])) { if (trim($zcommands) == null) { continue; } if (preg_match("#^(.+?)\\s+#", $zcommands, $re)) { if (!$AlreadyTests[$fileTests]) { $fileTests = trim("{$re[1]}"); if (!is_file($fileTests)) { events("running {$fileTests} No such file", __FUNCTION__, __LINE__); continue; } else { $AlreadyTests[$fileTests] = true; } } } if (!$already[$zcommands]) { $tbl[] = $zcommands; $already[$zcommands] = true; } } @file_put_contents('/etc/artica-postfix/background', implode("\n", $tbl)); unset($GLOBALS["CMDS"]); $mem = round(memory_get_usage() / 1024 / 1000, 2); if ($GLOBALS["EnableArticaBackground"]) { $EnableArticaBackground = "Has daemon mode..."; } else { $EnableArticaBackground = "Has cmdline mode..."; } events("Saving /etc/artica-postfix/background done... Memory of this computer={$GLOBALS["TOTAL_MEMORY_MB"]}M Process memory at the end={$mem} Mb EnableArticaBackground=`{$EnableArticaBackground}`", __FUNCTION__, __LINE__); } @file_put_contents("/etc/artica-postfix/pids/" . basename(__FILE__) . ".GLOBALS", serialize($GLOBALS["TIME"])); }