From 53424c50bfd8a946dbce3c5231d8fbcb6e85bdee Mon Sep 17 00:00:00 2001 From: jeroen Date: Wed, 21 Sep 2022 16:33:29 +0200 Subject: [PATCH] ENHANCEMENT: daemon cannot be checked if run in a different container --- src/Command/DaemonCommand.php | 3 ++- src/Service/DaemonHelpers.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Command/DaemonCommand.php b/src/Command/DaemonCommand.php index 66931d6..629b6e3 100644 --- a/src/Command/DaemonCommand.php +++ b/src/Command/DaemonCommand.php @@ -50,7 +50,7 @@ class DaemonCommand extends Command throw new \InvalidArgumentException('Time limit has incorrect value'); } $jobRepo->unlockJob(); - file_put_contents($this->kernel->getCacheDir() . '/daemon-running.lock', posix_getpid()); + file_put_contents($this->kernel->getCacheDir() . '/daemon-running.lock', time()); while(1) { if($endofscript !== false && time() > $endofscript) break; @@ -86,6 +86,7 @@ class DaemonCommand extends Command } } $this->doctrine->getManager()->clear(); + file_put_contents($this->kernel->getCacheDir() . '/daemon-running.lock', time()); $maxwait = time() + 30; $nextrun = $jobRepo->getTimeOfNextRun(); diff --git a/src/Service/DaemonHelpers.php b/src/Service/DaemonHelpers.php index 0eb5bdc..a3a5513 100644 --- a/src/Service/DaemonHelpers.php +++ b/src/Service/DaemonHelpers.php @@ -14,8 +14,8 @@ class DaemonHelpers */ public static function isProcessRunning($pidFile = '/var/run/myfile.pid') { if (!file_exists($pidFile) || !is_file($pidFile)) return false; - $pid = file_get_contents($pidFile); - $return = posix_kill((int)$pid, 0); + $lasttick = file_get_contents($pidFile); + $return = ((int)$lasttick >= (time() - 30)); if (!$return) unlink($pidFile); return $return; }