From 7e59b6f0d05d8e15acb7e09519193762c70462b1 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 23 Aug 2018 14:28:44 -0400 Subject: [PATCH] increment port multiple times if multiple embarks --- lib/modules/webserver/index.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index a00149196..8fd62d734 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -18,12 +18,7 @@ class WebServer { this.events.emit("status", __("Starting Server")); - utils.pingEndpoint(this.host, this.port, 'http', 'http', '', (err) => { - if (!err) { // Port already in use - this.logger.warn(__('Webserver already running on port {{oldPort}}. Trying to connect on {{newPort}}', - {oldPort: this.port, newPort: this.port + 1})); - this.port++; - } + this.testPort(() => { this.server = new Server({host: this.host, port: this.port}); this.setServiceCheck(); @@ -33,6 +28,18 @@ class WebServer { }); } + testPort(done) { + utils.pingEndpoint(this.host, this.port, 'http', 'http', '', (err) => { + if (err) { // Port is ok + return done(); + } + this.logger.warn(__('Webserver already running on port {{oldPort}}. Trying to connect on {{newPort}}', + {oldPort: this.port, newPort: this.port + 1})); + this.port++; + this.testPort(done); + }); + } + setServiceCheck() { let url = 'http://' + canonicalHost(this.host) + ':' + this.port;