pull/844/head
TimZ99 2020-02-04 16:40:08 +01:00
parent b668a0b842
commit ee5ab3a9ab
No known key found for this signature in database
GPG Key ID: 4D8268DC68E8339D
1 changed files with 49 additions and 43 deletions

View File

@ -28,10 +28,10 @@
namespace { namespace {
// include main configuration and functionality // include main configuration and functionality
use psm\Router; use psm\Router;
use psm\Util\Server\UpdateManager; use psm\Util\Server\UpdateManager;
require_once __DIR__ . '/../src/bootstrap.php'; require_once __DIR__ . '/../src/bootstrap.php';
if (!psm_is_cli()) { if (!psm_is_cli()) {
// check if it's an allowed host // check if it's an allowed host
@ -85,37 +85,43 @@ namespace {
// if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php. // if you want to change PSM_CRON_TIMEOUT, have a look in src/includes/psmconfig.inc.php.
// or you can provide the --timeout=x argument // or you can provide the --timeout=x argument
$status = null; $status = null;
if (PHP_SAPI === 'cli') { if (PHP_SAPI === 'cli') {
$shortOptions = 's:'; // status $shortOptions = 's:'; // status
$longOptions = [ $longOptions = [
'status:' 'status:'
]; ];
$options = getopt($shortOptions, $longOptions); $options = getopt($shortOptions, $longOptions);
$possibleValues = [ $possibleValues = [
'on' => 'on', 'on' => 'on',
'1' => 'on', '1' => 'on',
'up' => 'on', 'up' => 'on',
'off' => 'off', 'off' => 'off',
'0' => 'off', '0' => 'off',
'down' => 'off' 'down' => 'off'
]; ];
if (true === array_key_exists('status', $options) && true === array_key_exists(strtolower($options['status']), $possibleValues)) { if (
$status = $possibleValues[$options['status']]; true === array_key_exists('status', $options) &&
} else if (true === array_key_exists('s', $options) && true === array_key_exists(strtolower($options['s']), $possibleValues)) { true === array_key_exists(strtolower($options['status']), $possibleValues)
$status = $possibleValues[$options['s']]; ) {
} $status = $possibleValues[$options['status']];
} } elseif (
true === array_key_exists('s', $options) &&
true === array_key_exists(strtolower($options['s']), $possibleValues)
) {
$status = $possibleValues[$options['s']];
}
}
if ($status === 'off') { if ($status === 'off') {
$confPrefix = 'cron_off_'; $confPrefix = 'cron_off_';
} else { } else {
$confPrefix = 'cron_'; $confPrefix = 'cron_';
} }
$time = time(); $time = time();
if ( if (
@ -135,21 +141,21 @@ namespace {
$autorun = $router->getService('util.server.updatemanager'); $autorun = $router->getService('util.server.updatemanager');
if ($status !== 'off') { if ($status !== 'off') {
$autorun->run(true, $status); $autorun->run(true, $status);
} else { } else {
set_time_limit(60); set_time_limit(60);
if (false === defined('CRON_DOWN_INTERVAL')) { if (false === defined('CRON_DOWN_INTERVAL')) {
define('CRON_DOWN_INTERVAL', 5); // every 5 second call update define('CRON_DOWN_INTERVAL', 5); // every 5 second call update
} }
$start = time(); $start = time();
$i = 0; $i = 0;
while ($i < 59) { while ($i < 59) {
$autorun->run(true, $status); $autorun->run(true, $status);
if ($i < (59 - CRON_DOWN_INTERVAL)) { if ($i < (59 - CRON_DOWN_INTERVAL)) {
time_sleep_until($start + $i + CRON_DOWN_INTERVAL); time_sleep_until($start + $i + CRON_DOWN_INTERVAL);
} }
$i += CRON_DOWN_INTERVAL; $i += CRON_DOWN_INTERVAL;
} }
} }
psm_update_conf($confPrefix . 'running', 0); psm_update_conf($confPrefix . 'running', 0);