From 74d7d7e164364c09b7fdfbf64e15168ccd56508a Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 3 Jan 2021 22:57:25 +0000 Subject: [PATCH] Check for childf status --- bin/daemon.php | 3 +++ src/Core/Worker.php | 27 ++++++++++++++++++--------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bin/daemon.php b/bin/daemon.php index ec507305cc..cc86a9f201 100755 --- a/bin/daemon.php +++ b/bin/daemon.php @@ -223,6 +223,9 @@ while (true) { $sleep = min(1000000, round(log10($arg) * 1000000, 0)); usleep($sleep); + $pid = pcntl_waitpid(-1, $status, WNOHANG); + Logger::info('Checked children status via pcntl_waitpid', ['pid' => $pid, 'status' => $status]); + $timeout = ($seconds >= $wait_interval); } while (!$timeout && !Worker::IPCJobsExists()); diff --git a/src/Core/Worker.php b/src/Core/Worker.php index ec317a676d..559ae68370 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -1230,6 +1230,17 @@ class Worker DI::process()->end(); Logger::info('Worker ended', ['cron' => $do_cron, 'pid' => getmypid()]); + + DBA::disconnect(); +/* + $php = '/usr/bin/php'; + $param = ['bin/worker.php']; + if ($do_cron) { + $param[] = 'no_cron'; + } + pcntl_exec($php, $param); + Logger::warning('Error calling worker', ['cron' => $do_cron, 'pid' => getmypid()]); +*/ exit(); } @@ -1242,21 +1253,14 @@ class Worker */ public static function spawnWorker($do_cron = false) { - Logger::notice("Spawn", ['do_cron' => $do_cron, 'callstack' => System::callstack(20)]); - // Worker and daemon are started from the command line. - // This means that this is executed by a PHP interpreter without runtime limitations - if (function_exists('pcntl_fork') && in_array(DI::mode()->getExecutor(), [Mode::DAEMON, Mode::WORKER])) { + if (self::isDaemonMode()) { self::forkProcess($do_cron); + self::IPCSetJobState(false); } else { $process = new Core\Process(DI::logger(), DI::mode(), DI::config(), DI::modelProcess(), DI::app()->getBasePath(), getmypid()); $process->run('bin/worker.php', ['no_cron' => !$do_cron]); } - - // after spawning we have to remove the flag. - if (self::isDaemonMode()) { - self::IPCSetJobState(false); - } } /** @@ -1515,6 +1519,11 @@ class Worker return $daemon_mode; } + if (!function_exists('pcntl_fork')) { + self::$daemon_mode = false; + return false; + } + $pidfile = DI::config()->get('system', 'pidfile'); if (empty($pidfile)) { // No pid file, no daemon