From a38c317ecdb9266731708c397f0c017087a5d99b Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 23 Aug 2018 14:14:10 -0400 Subject: [PATCH] check port for webserver, if in use ++ port --- lib/modules/webserver/index.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/modules/webserver/index.js b/lib/modules/webserver/index.js index cfd5d7ba..a0014919 100644 --- a/lib/modules/webserver/index.js +++ b/lib/modules/webserver/index.js @@ -17,14 +17,20 @@ class WebServer { this.port = options.port || this.webServerConfig.port; this.events.emit("status", __("Starting Server")); - this.server = new Server({host: this.host, port: this.port}); - this.setServiceCheck(); - this.listenToCommands(); - this.registerConsoleCommands(); + 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.server = new Server({host: this.host, port: this.port}); - let self = this; - this.server.start((_err, message) => self.logger.info(message)); + this.setServiceCheck(); + this.listenToCommands(); + this.registerConsoleCommands(); + this.server.start((_err, message) => this.logger.info(message)); + }); } setServiceCheck() {