From 2d288495dc3e498751ac4b6573da0d84b44dc6c0 Mon Sep 17 00:00:00 2001 From: Joe Bidon Date: Mon, 27 Nov 2017 09:35:26 +0100 Subject: [PATCH] =?UTF-8?q?V=C3=A9rification=20que=20le=20pid=20existe=20s?= =?UTF-8?q?ur=20les=20lockfiles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si le process "check.php" des alertes s'arrête anormalement pour une raison X ou Y, le fichier var/.lock reste actif et cela bloque les lancements futur du process check.php. Ce commit propose de tester si le pid stocké dans le fichier de .lock existe vraiment avant de statuer que le process est en cours d'exécution. --- app/notifier/scripts/check.php | 36 ++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/notifier/scripts/check.php b/app/notifier/scripts/check.php index bd04c9a..9e2fe96 100644 --- a/app/notifier/scripts/check.php +++ b/app/notifier/scripts/check.php @@ -48,8 +48,7 @@ public function __construct( $this->_lockFile = DOCUMENT_ROOT."/var/.lock"; $this->_lock(); - $this->_running = true; - + $this->_running = true; $this->_logger->info("[Pid ".getmypid()."] Vérification des alertes."); $this->_mailer = new PHPMailer($exceptions=true); @@ -129,15 +128,15 @@ public function check() $baseurl = $this->_config->get("general", "baseurl", ""); - foreach ($users AS $user) { - if ($storageType == "db") { + foreach ($users AS $user) { + if ($storageType == "db") { $storage = new \App\Storage\Db\Alert($this->_userStorage->getDbConnection(), $user); - $this->_logger->info("[Pid ".getmypid()."] USER : ".$user->getUsername()); - } else { + $this->_logger->info("[Pid ".getmypid()."] USER : ".$user->getUsername()); + } else { $file = DOCUMENT_ROOT."/var/configs/".$user->getUsername().".csv"; if (!is_file($file)) { continue; - } + } $storage = new \App\Storage\File\Alert($file); $this->_logger->info("[Pid ".getmypid()."] USER : ".$user->getUsername()." (".$file.")"); } @@ -539,8 +538,16 @@ protected function _checkConnection() protected function _lock() { + + if (is_file($this->_lockFile)) { + $content = file_get_contents($this->_lockFile); + //on vérifie que le pid existe vraiment + if(posix_kill(explode("\n",$content)[1], 0)){ throw new Exception("Un processus est en cours d'exécution."); + }else{ + Logger::getLogger("main")->info("Le précédent process s'est interrompu de manière anormale."); + } } file_put_contents($this->_lockFile, time()."\n".getmypid()); return $this; @@ -565,17 +572,12 @@ protected function _lock() return; } -try { - $main = new Main($config, $client, $userStorage); +try { + $main = new Main($config, $client, $userStorage); } catch (\Exception $e) { - Logger::getLogger("main")->info($e->getMessage()); - return; -} + Logger::getLogger("main")->info($e->getMessage()); + return; +} $main->check(); $main->shutdown(); - - - - -