Skip to content

Commit 9400064

Browse files
authored
Merge pull request #89 from le-phare/process-alpine
fix(process-check): support Alpine Linux ps command
2 parents 22288b6 + aee33e5 commit 9400064

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/Check/ProcessRunning.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use Laminas\Diagnostics\Result\ResultInterface;
88
use Laminas\Diagnostics\Result\Success;
99

10-
use function escapeshellarg;
1110
use function exec;
1211
use function gettype;
1312
use function is_numeric;
1413
use function is_scalar;
1514
use function sprintf;
15+
use function str_contains;
1616

1717
/**
1818
* Check if a process with given name or ID is currently running.
@@ -94,12 +94,23 @@ private function checkAgainstPid()
9494
*/
9595
private function checkAgainstProcessName()
9696
{
97-
exec('ps -efww | grep ' . escapeshellarg($this->processName) . ' | grep -v grep', $output, $return);
97+
/**
98+
* @see https://man7.org/linux/man-pages/ps.1.html (search for 'ps -eo') for GNU implementation
99+
* @see https://busybox.net/downloads/BusyBox.html (search for 'ps') for BusyBox implementation
100+
*/
101+
exec('ps -eo pid,args', $output, $return);
98102

99103
if ($return > 0) {
100104
return new Failure(sprintf('Could not find any running process containing "%s"', $this->processName));
101105
}
102106

103-
return new Success();
107+
/** @var string $line */
108+
foreach ($output as $line) {
109+
if (str_contains($line, $this->processName)) {
110+
return new Success();
111+
}
112+
}
113+
114+
return new Failure(sprintf('Could not find any running process containing "%s"', $this->processName));
104115
}
105116
}

0 commit comments

Comments
 (0)