ENHANCEMENT: daemon cannot be checked if run in a different container

This commit is contained in:
Jeroen De Meerleer 2022-09-21 16:33:29 +02:00
parent 9fea685e86
commit 53424c50bf
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 4 additions and 3 deletions

View File

@ -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();

View File

@ -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;
}