From def52dea126ff598087d443f3c838cc4163f4bfd Mon Sep 17 00:00:00 2001 From: Joel Van Horn Date: Mon, 25 Sep 2023 15:36:39 -0400 Subject: [PATCH 1/4] Forward signal to process --- src/Commands/WatchHorizonCommand.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Commands/WatchHorizonCommand.php b/src/Commands/WatchHorizonCommand.php index 9be6e69..b057c71 100644 --- a/src/Commands/WatchHorizonCommand.php +++ b/src/Commands/WatchHorizonCommand.php @@ -20,13 +20,7 @@ public function handle() { $this->components->info('Starting Horizon and will restart it when any files change...'); - $this->trap([SIGINT, SIGTERM], function ($signal): void { - $this->trappedSignal = $signal; - }); - - $horizonStarted = $this->startHorizon(); - - if (! $horizonStarted) { + if (! $this->startHorizon()) { return Command::FAILURE; } @@ -35,9 +29,16 @@ public function handle() protected function startHorizon(): bool { - $this->horizonProcess = Process::fromShellCommandline(config('horizon-watcher.command')); + $this->horizonProcess = Process::fromShellCommandline(config('horizon-watcher.command')) + ->setTty(! $this->option('without-tty')) + ->setTimeout(null); - $this->horizonProcess->setTty(! $this->option('without-tty'))->setTimeout(null); + $this->trap([SIGINT, SIGTERM], function ($signal): void { + $this->trappedSignal = $signal; + + // Forward signal to Horizon process. + $this->horizonProcess->stop(signal: $signal); + }); $this->horizonProcess->start(fn ($type, $output) => $this->info($output)); From 173cae27a6f74687d7ab441d9c284512b29af63c Mon Sep 17 00:00:00 2001 From: Joel Van Horn Date: Tue, 26 Sep 2023 12:25:40 -0400 Subject: [PATCH 2/4] Trap more signals --- src/Commands/WatchHorizonCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/WatchHorizonCommand.php b/src/Commands/WatchHorizonCommand.php index b057c71..ffeb15c 100644 --- a/src/Commands/WatchHorizonCommand.php +++ b/src/Commands/WatchHorizonCommand.php @@ -33,7 +33,7 @@ protected function startHorizon(): bool ->setTty(! $this->option('without-tty')) ->setTimeout(null); - $this->trap([SIGINT, SIGTERM], function ($signal): void { + $this->trap([SIGINT, SIGTERM, SIGQUIT, SIGKILL], function ($signal): void { $this->trappedSignal = $signal; // Forward signal to Horizon process. From c9df4dfbed7983b99b10d3f1eeb74eb18664c405 Mon Sep 17 00:00:00 2001 From: Joel Van Horn Date: Tue, 26 Sep 2023 12:25:56 -0400 Subject: [PATCH 3/4] Wait for process to quit --- src/Commands/WatchHorizonCommand.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Commands/WatchHorizonCommand.php b/src/Commands/WatchHorizonCommand.php index ffeb15c..2c3980a 100644 --- a/src/Commands/WatchHorizonCommand.php +++ b/src/Commands/WatchHorizonCommand.php @@ -38,6 +38,7 @@ protected function startHorizon(): bool // Forward signal to Horizon process. $this->horizonProcess->stop(signal: $signal); + $this->horizonProcess->wait(); }); $this->horizonProcess->start(fn ($type, $output) => $this->info($output)); @@ -83,6 +84,7 @@ protected function restartHorizon(): self $this->components->info('Change detected! Restarting horizon...'); $this->horizonProcess->stop(); + $this->horizonProcess->wait(); $this->startHorizon(); From 78a7c89c69300a7ed230eb5d35679c6bd00aa1ec Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Tue, 24 Oct 2023 08:42:04 +0200 Subject: [PATCH 4/4] Remove SIGKILL --- src/Commands/WatchHorizonCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/WatchHorizonCommand.php b/src/Commands/WatchHorizonCommand.php index 2c3980a..643a835 100644 --- a/src/Commands/WatchHorizonCommand.php +++ b/src/Commands/WatchHorizonCommand.php @@ -33,7 +33,7 @@ protected function startHorizon(): bool ->setTty(! $this->option('without-tty')) ->setTimeout(null); - $this->trap([SIGINT, SIGTERM, SIGQUIT, SIGKILL], function ($signal): void { + $this->trap([SIGINT, SIGTERM, SIGQUIT], function ($signal): void { $this->trappedSignal = $signal; // Forward signal to Horizon process.