Skip to content

Commit dd9f955

Browse files
authored
Merge pull request #9 from sdapkus/main
Kill child processes before exiting horizon
2 parents 09bf9d3 + e0d5402 commit dd9f955

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/Commands/WatchHorizonCommand.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ protected function restartHorizon(): self
7272
{
7373
$this->components->info('Change detected! Restarting horizon...');
7474

75-
$this->horizonProcess->stop();
76-
75+
$this->stopHorizon();
7776
$this->startHorizon();
7877

7978
return $this;
@@ -83,4 +82,26 @@ protected function isPhpFile(string $path): bool
8382
{
8483
return str_ends_with(strtolower($path), '.php');
8584
}
85+
86+
protected function stopHorizon(): void
87+
{
88+
$this->killStrayHorizonProcesses();
89+
90+
$this->horizonProcess->stop();
91+
}
92+
93+
protected function killStrayHorizonProcesses(): void
94+
{
95+
(Process::fromShellCommandline('pgrep -P ' . $this->horizonProcess->getPid()))
96+
->run(function ($type, $output) {
97+
$childPids = explode("\n", $output);
98+
foreach ($childPids as $childPid) {
99+
if (! $childPid) {
100+
continue;
101+
}
102+
103+
(Process::fromShellCommandline('kill ' . $childPid))->run();
104+
}
105+
});
106+
}
86107
}

0 commit comments

Comments
 (0)