Skip to content

Commit 44b3ae6

Browse files
authored
Fixes RR reload by setting a different RPC port (#216)
1 parent dbe481b commit 44b3ae6

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/Commands/StartCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class StartCommand extends Command implements SignalableCommandInterface
1717
{--server= : The server that should be used to serve the application}
1818
{--host=127.0.0.1 : The IP address the server should bind to}
1919
{--port=8000 : The port the server should be available on}
20+
{--rpc-port= : The RPC port the server should be available on}
2021
{--workers=auto : The number of workers that should be available to handle requests}
2122
{--task-workers=auto : The number of task workers that should be available to handle tasks}
2223
{--max-requests=500 : The number of requests to process before reloading the server}
@@ -79,6 +80,7 @@ protected function startRoadRunnerServer()
7980
return $this->call('octane:roadrunner', [
8081
'--host' => $this->option('host'),
8182
'--port' => $this->option('port'),
83+
'--rpc-port' => $this->option('rpc-port'),
8284
'--workers' => $this->option('workers'),
8385
'--max-requests' => $this->option('max-requests'),
8486
'--watch' => $this->option('watch'),

src/Commands/StartRoadRunnerCommand.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class StartRoadRunnerCommand extends Command implements SignalableCommandInterfa
2121
public $signature = 'octane:roadrunner
2222
{--host=127.0.0.1 : The IP address the server should bind to}
2323
{--port=8000 : The port the server should be available on}
24+
{--rpc-port= : The RPC port the server should be available on}
2425
{--workers=auto : The number of workers that should be available to handle requests}
2526
{--max-requests=500 : The number of requests to process before reloading the server}
2627
{--watch : Automatically reload the server when the application is modified}';
@@ -73,6 +74,7 @@ public function handle(ServerProcessInspector $inspector, ServerStateFile $serve
7374
'-o', 'server.command='.(new PhpExecutableFinder)->find().' ./vendor/bin/roadrunner-worker',
7475
'-o', 'http.pool.num_workers='.$this->workerCount(),
7576
'-o', 'http.pool.max_jobs='.$this->option('max-requests'),
77+
'-o', 'rpc.listen=tcp://'.$this->option('host').':'.$this->rpcPort(),
7678
'-o', 'http.pool.supervisor.exec_ttl='.$this->maxExecutionTime(),
7779
'-o', 'http.static.dir=public',
7880
'-o', 'http.middleware=static',
@@ -101,6 +103,7 @@ protected function writeServerStateFile(
101103
'appName' => config('app.name', 'Laravel'),
102104
'host' => $this->option('host'),
103105
'port' => $this->option('port'),
106+
'rpcPort' => $this->rpcPort(),
104107
'workers' => $this->workerCount(),
105108
'maxRequests' => $this->option('max-requests'),
106109
'octaneConfig' => config('octane'),
@@ -129,6 +132,16 @@ protected function maxExecutionTime()
129132
return config('octane.max_execution_time', '30').'s';
130133
}
131134

135+
/**
136+
* Get the RPC port the server should be available on.
137+
*
138+
* @return int
139+
*/
140+
protected function rpcPort()
141+
{
142+
return $this->option('rpc-port') ?: $this->option('port') - 1999;
143+
}
144+
132145
/**
133146
* Write the server process output to the console.
134147
*

src/RoadRunner/ServerProcessInspector.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ public function serverIsRunning(): bool
3737
*/
3838
public function reloadServer(): void
3939
{
40-
tap($this->processFactory->createProcess(
41-
['./rr', 'reset'],
42-
base_path()
43-
))->start()->waitUntil(function ($type, $buffer) {
40+
[
41+
'state' => [
42+
'host' => $host,
43+
'rpcPort' => $rpcPort,
44+
],
45+
] = $this->serverStateFile->read();
46+
47+
tap($this->processFactory->createProcess([
48+
'./rr',
49+
'reset',
50+
'-o', "rpc.listen=tcp://$host:$rpcPort",
51+
], base_path()))->start()->waitUntil(function ($type, $buffer) {
4452
if ($type === Process::ERR) {
4553
throw new RuntimeException('Cannot reload RoadRunner: '.$buffer);
4654
}

tests/RoadRunnerServerProcessInspectorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ public function test_roadrunner_server_process_can_be_reloaded()
5555
new PosixExtension
5656
);
5757

58+
$processIdFile->writeState([
59+
'host' => '127.0.0.1',
60+
'rpcPort' => '6002',
61+
]);
62+
5863
$processFactory->shouldReceive('createProcess')->with(
59-
['./rr', 'reset'],
64+
['./rr', 'reset', '-o', 'rpc.listen=tcp://127.0.0.1:6002'],
6065
base_path(),
6166
)->andReturn($process = Mockery::mock('stdClass'));
6267

0 commit comments

Comments
 (0)