diff --git a/metager/app/Console/Commands/FPMGracefulStop.php b/metager/app/Console/Commands/FPMGracefulStop.php index 1d752bd8cad1bc5c85505c44c45cf03ac64a0745..37626e1e5fc2be3ca9db201167324ea5c03fd781 100644 --- a/metager/app/Console/Commands/FPMGracefulStop.php +++ b/metager/app/Console/Commands/FPMGracefulStop.php @@ -2,10 +2,13 @@ namespace App\Console\Commands; +use ErrorException; use Illuminate\Console\Command; +use Illuminate\Support\Facades\Redis; class FPMGracefulStop extends Command { + const REDIS_FPM_STOPPED_KEY = "fpm_stopped"; /** * The name and signature of the console command. * @@ -33,6 +36,11 @@ class FPMGracefulStop extends Command } while ($active_fpm_processes === null || $active_fpm_processes > 1); $this->info("Only one FPM process left. Ready to stop fpm..."); + // The Request fetcher won't stop before FPM is not stopped with processing requests + // because there could be last jobs flying in + // This Redis Value will tell him that it's good to stop + Redis::set(self::REDIS_FPM_STOPPED_KEY, "true"); + $this->info("Set Redis Key"); return 0; } @@ -51,8 +59,12 @@ class FPMGracefulStop extends Command "header" => "Authorization: Basic $auth", ], ]); - - $fpm_info = \file_get_contents($url, false, $context); + try { + $fpm_info = \file_get_contents($url, false, $context); + } catch (ErrorException $e) { + // Webserver could not be reached. Probably already shut down so there are no active connections anyways + return 0; + } if ($fpm_info !== false) { $fpm_info = \json_decode($fpm_info); } else { diff --git a/metager/app/Console/Commands/RequestFetcher.php b/metager/app/Console/Commands/RequestFetcher.php index 40c9eb31055a10e4fe2dfafcc7b0614e5e25106e..b646cb6f49fdccd7ed66a3a05585d9df35b4792a 100644 --- a/metager/app/Console/Commands/RequestFetcher.php +++ b/metager/app/Console/Commands/RequestFetcher.php @@ -84,7 +84,8 @@ class RequestFetcher extends Command if ($newJobs === 0 && $answersRead === 0) { usleep(10 * 1000); } - if (!$this->shouldRun && $operationsRunning === 0) { + + if (!$this->shouldRun && $operationsRunning === 0 && Redis::get(FPMGracefulStop::REDIS_FPM_STOPPED_KEY) !== NULL) { break; } } @@ -234,8 +235,7 @@ class RequestFetcher extends Command public function sig_handler($sig) { - $this->info("Received Shutdown signal"); $this->shouldRun = false; - echo ("Terminating Process\n"); + $this->info("Terminating Process\n"); } }