increment port multiple times if multiple embarks

This commit is contained in:
Jonathan Rainville 2018-08-23 14:28:44 -04:00
parent a38c317ecd
commit 7e59b6f0d0
1 changed files with 13 additions and 6 deletions

View File

@ -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;