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