check port for webserver, if in use ++ port

This commit is contained in:
Jonathan Rainville 2018-08-23 14:14:10 -04:00
parent fa551f67a3
commit a38c317ecd
1 changed files with 12 additions and 6 deletions

View File

@ -17,14 +17,20 @@ class WebServer {
this.port = options.port || this.webServerConfig.port; this.port = options.port || this.webServerConfig.port;
this.events.emit("status", __("Starting Server")); this.events.emit("status", __("Starting Server"));
this.server = new Server({host: this.host, port: this.port});
this.setServiceCheck(); utils.pingEndpoint(this.host, this.port, 'http', 'http', '', (err) => {
this.listenToCommands(); if (!err) { // Port already in use
this.registerConsoleCommands(); 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.setServiceCheck();
this.server.start((_err, message) => self.logger.info(message)); this.listenToCommands();
this.registerConsoleCommands();
this.server.start((_err, message) => this.logger.info(message));
});
} }
setServiceCheck() { setServiceCheck() {