mirror of
https://github.com/laravel/valet.git
synced 2026-02-05 00:20:08 +01:00
Stop root homebrew services on php version switch
Before the change, when running `valet use` the code intended to stop currently running PHP services. But the `getRunningServices` method only returned non-root running services. As PHP services started by Valet are run using `sudo` (so running as root), they were not returned and subsequently not stopped. This change is intended to fix the above and stop PHP services that are started by Valet on a PHP version switch.
This commit is contained in:
@@ -371,20 +371,58 @@ function ($exitCode, $errorOutput) use ($formula) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently running brew services.
|
||||
* Get all the currently running brew services.
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getRunningServices()
|
||||
public function getAllRunningServices()
|
||||
{
|
||||
return collect(array_filter(explode(PHP_EOL, $this->cli->runAsUser(
|
||||
'brew services list | grep started | awk \'{ print $1; }\'',
|
||||
function ($exitCode, $errorOutput) {
|
||||
output($errorOutput);
|
||||
return $this->getRunningServicesAsRoot()
|
||||
->concat($this->getRunningServicesAsUser())
|
||||
->unique();
|
||||
}
|
||||
|
||||
throw new DomainException('Brew was unable to check which services are running.');
|
||||
}
|
||||
))));
|
||||
/**
|
||||
* Get the currently running brew services as root.
|
||||
* i.e. /Library/LaunchDaemons (started at boot)
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getRunningServicesAsRoot()
|
||||
{
|
||||
return $this->getRunningServices();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently running brew services.
|
||||
* i.e. ~/Library/LaunchAgents (started at login)
|
||||
*
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getRunningServicesAsUser()
|
||||
{
|
||||
return $this->getRunningServices(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the currently running brew services.
|
||||
*
|
||||
* @param bool $asUser
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function getRunningServices(bool $asUser = false)
|
||||
{
|
||||
$command = 'brew services list | grep started | awk \'{ print $1; }\'';
|
||||
$onError = function ($exitCode, $errorOutput) {
|
||||
output($errorOutput);
|
||||
|
||||
throw new DomainException('Brew was unable to check which services are running.');
|
||||
};
|
||||
|
||||
return collect(array_filter(explode(PHP_EOL, $asUser
|
||||
? $this->cli->runAsUser($command, $onError)
|
||||
: $this->cli->run('sudo ' . $command, $onError)
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user