From 259a4122369a08509911a564f93bbdc1082fa48b Mon Sep 17 00:00:00 2001 From: Xantios Krugor Date: Sat, 3 Jul 2021 15:13:45 +0200 Subject: [PATCH] Added host property and made port optional --- maple-config.example.php | 52 ++++++++++++++++++++++++++++++++-------- readme.md | 7 ++++-- src/HttpServer.php | 7 ++++-- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/maple-config.example.php b/maple-config.example.php index 57a18fe..267fc27 100644 --- a/maple-config.example.php +++ b/maple-config.example.php @@ -1,14 +1,46 @@ "Some long running thing", - 'retries' => 3, - 'autostart' => true - ], - [ - 'name' => "Some process that keeps on exiting but needs to be running", - 'reties' => -1, - 'autostart' => true + + // Host to listen on (defaults to 127.0.0.1) + # 'host' => '0.0.0.0', + + // Port for web interface to listen on (defaults to 8100) + # 'port' => 8100, + + // Verbose logging + 'verbose' => true, + + // Tasks available + 'tasks' => [ + [ + 'name' => "Run webpack", + 'retries' => 0, + 'autostart' => true, + 'cmd' => 'sleep 10' + ], + [ + 'name' => "Some process that keeps on exiting but needs to be running", + 'retries' => -1, + 'autostart' => true, + 'cmd' => 'ping -t 3 8.8.8.8 ; sleep 5' + ], + // Run multiple tasks back-to-back + [ + 'name' => 'Jan-1', + 'after' => 'Jan-2', + 'autostart' => true, + 'cmd' => 'sleep 1', + ], + [ + 'name' => 'Jan-2', + 'after' => 'Jan-3', + 'cmd' => 'sleep 1', + ], + [ + 'name' => 'Jan-3', + 'after' => '', + 'cmd' => 'sleep 1', + ] ] -]; \ No newline at end of file +]; diff --git a/readme.md b/readme.md index 693c444..f521c75 100644 --- a/readme.md +++ b/readme.md @@ -34,8 +34,11 @@ The configuration file is a plain PHP array, it is pretty self-explanatory 8100, + // Host to listen on (defaults to 127.0.0.1) + # 'host' => '0.0.0.0', + + // Port for web interface to listen on (defaults to 8100) + # 'port' => 8100, // Verbose logging 'verbose' => true, diff --git a/src/HttpServer.php b/src/HttpServer.php index 5815709..7cc538b 100644 --- a/src/HttpServer.php +++ b/src/HttpServer.php @@ -12,6 +12,7 @@ class HttpServer { private int $port; + private string $host; private LoopInterface $loop; private Server $server; @@ -19,7 +20,9 @@ class HttpServer { public function __construct(array $config,LoopInterface $loop,OutputInterface $output) { - $this->port = $config['port']; + $this->port = (isset($config['port'])) ? $config['port'] : '8100'; + $this->host = (isset($config['host'])) ? $config['host'] : '127.0.0.1'; + $this->loop = $loop; $this->output = $output; @@ -52,7 +55,7 @@ public function __construct(array $config,LoopInterface $loop,OutputInterface $o public function run(): void { $socket = new \React\Socket\Server($this->port,$this->loop); - $this->output->writeln('Listening on port '.$this->port.''); + $this->output->writeln('Listening on '.$this->host.":".$this->port.''); $this->server->listen($socket); }