diff --git a/src/Commands/WatchHorizonCommand.php b/src/Commands/WatchHorizonCommand.php index 9be6e69..643a835 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,17 @@ 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, SIGQUIT], function ($signal): void { + $this->trappedSignal = $signal; + + // Forward signal to Horizon process. + $this->horizonProcess->stop(signal: $signal); + $this->horizonProcess->wait(); + }); $this->horizonProcess->start(fn ($type, $output) => $this->info($output)); @@ -82,6 +84,7 @@ protected function restartHorizon(): self $this->components->info('Change detected! Restarting horizon...'); $this->horizonProcess->stop(); + $this->horizonProcess->wait(); $this->startHorizon();