Skip to content

Commit

Permalink
Addresses #332: pass config-file path for roadrunner (#335)
Browse files Browse the repository at this point in the history
* Addresses #332: pass config-file path for roadrunner

* style

* check absolute path

* foramtting

Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
  • Loading branch information
kevincobain2000 and taylorotwell committed Jul 5, 2021
1 parent 7c56189 commit a4e9602
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Commands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class StartCommand extends Command implements SignalableCommandInterface
{--workers=auto : The number of workers that should be available to handle requests}
{--task-workers=auto : The number of task workers that should be available to handle tasks}
{--max-requests=500 : The number of requests to process before reloading the server}
{--config= : The path to the RoadRunner .rr.yaml file}
{--watch : Automatically reload the server when the application is modified}';

/**
Expand Down Expand Up @@ -76,6 +77,7 @@ protected function startRoadRunnerServer()
'--rpc-port' => $this->option('rpc-port'),
'--workers' => $this->option('workers'),
'--max-requests' => $this->option('max-requests'),
'--config' => $this->option('config'),
'--watch' => $this->option('watch'),
]);
}
Expand Down
28 changes: 25 additions & 3 deletions src/Commands/StartRoadRunnerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Laravel\Octane\Commands;

use Illuminate\Support\Str;
use InvalidArgumentException;
use Laravel\Octane\RoadRunner\ServerProcessInspector;
use Laravel\Octane\RoadRunner\ServerStateFile;
use Symfony\Component\Console\Command\SignalableCommandInterface;
Expand All @@ -26,6 +27,7 @@ class StartRoadRunnerCommand extends Command implements SignalableCommandInterfa
{--rpc-port= : The RPC port the server should be available on}
{--workers=auto : The number of workers that should be available to handle requests}
{--max-requests=500 : The number of requests to process before reloading the server}
{--config= : The path to the RoadRunner .rr.yaml file}
{--watch : Automatically reload the server when the application is modified}';

/**
Expand Down Expand Up @@ -69,13 +71,11 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve

$this->writeServerStateFile($serverStateFile);

touch(base_path('.rr.yaml'));

$this->forgetEnvironmentVariables();

$server = tap(new Process(array_filter([
$roadRunnerBinary,
'-c', base_path('.rr.yaml'),
'-c', $this->configPath(),
'-o', 'http.address='.$this->option('host').':'.$this->option('port'),
'-o', 'server.command='.(new PhpExecutableFinder)->find().' ./vendor/bin/roadrunner-worker',
'-o', 'http.pool.num_workers='.$this->workerCount(),
Expand Down Expand Up @@ -132,6 +132,28 @@ protected function workerCount()
: $this->option('workers');
}

/**
* Get the path to the RoadRunner configuration file.
*
* @return string
*/
protected function configPath()
{
$path = $this->option('config');

if (! $path) {
touch(base_path('.rr.yaml'));

return base_path('.rr.yaml');
}

if ($path && ! realpath($path)) {
throw new InvalidArgumentException('Unable to locate specified configuration file.');
}

return realpath($path);
}

/**
* Get the maximum number of seconds that workers should be allowed to execute a single request.
*
Expand Down

0 comments on commit a4e9602

Please sign in to comment.