mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 19:18:44 +02:00
be able to call cron asynchronously
This commit is contained in:
39
webservices/cron_status.php
Normal file
39
webservices/cron_status.php
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(__DIR__.'/../approot.inc.php');
|
||||||
|
|
||||||
|
const RUNNING = "running";
|
||||||
|
const STOPPED = "stopped";
|
||||||
|
const ERROR = "error";
|
||||||
|
|
||||||
|
$sLogFilename = utils::ReadParam("cron_log_file", null, true, utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
|
||||||
|
if (is_null($sLogFilename)) {
|
||||||
|
$sLogFilename = utils::ReadPostedParam("cron_log_file", null, utils::ENUM_SANITIZATION_FILTER_RAW_DATA) ?? "cron.log";
|
||||||
|
}
|
||||||
|
$sLogFile = APPROOT . "log/$sLogFilename";
|
||||||
|
if (is_file($sLogFile)){
|
||||||
|
$sContent = exec("tail -n 1 $sLogFile");
|
||||||
|
if (0 === strpos($sContent, 'Exiting: ')){
|
||||||
|
exec("tail -n 2 $sLogFile", $aContent);
|
||||||
|
//var_dump($aContent);
|
||||||
|
$sContent = implode("\n", $aContent);
|
||||||
|
if (false !== strpos($sContent, 'Already running')){
|
||||||
|
echo ERROR . " (already running)";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preg_match('/ERROR: (.*)\\n/', $sContent, $aMatches)){
|
||||||
|
echo ERROR . " ($aMatches[1])";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "$sContent\n";
|
||||||
|
echo STOPPED;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo RUNNING;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo ERROR . "(missing $sLogFile)";
|
||||||
24
webservices/launch_cron_asynchronously.php
Normal file
24
webservices/launch_cron_asynchronously.php
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once(__DIR__.'/../approot.inc.php');
|
||||||
|
|
||||||
|
$sLogFilename = utils::ReadParam("cron_log_file", null, true, utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
|
||||||
|
if (is_null($sLogFilename)) {
|
||||||
|
$sLogFilename = utils::ReadPostedParam("cron_log_file", null, utils::ENUM_SANITIZATION_FILTER_RAW_DATA) ?? "cron.log";
|
||||||
|
}
|
||||||
|
$sLogFile = APPROOT . "log/$sLogFilename";
|
||||||
|
|
||||||
|
$sCliParams = utils::ReadParam("cron_cli_parameters", null, true, utils::ENUM_SANITIZATION_FILTER_RAW_DATA);
|
||||||
|
if (is_null($sCliParams)) {
|
||||||
|
$sCliParams = utils::ReadPostedParam("cron_cli_parameters", null, utils::ENUM_SANITIZATION_FILTER_RAW_DATA) ?? "--help";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_null($sCliParams)){
|
||||||
|
$sCliParams = "--help";
|
||||||
|
} else {
|
||||||
|
$sCliParams = base64_decode($sCliParams, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sCli = sprintf("php %s/cron.php $sCliParams 2>&1 >>$sLogFile &", __DIR__);
|
||||||
|
exec("echo $sCli>>$sLogFile");
|
||||||
|
$process=popen($sCli, 'r');
|
||||||
Reference in New Issue
Block a user