* Ping root url to retrieve node info * @private * @param {Function} cb invoked with [optional]
(cb)
| 329 | * @param {Function} cb invoked with <Error> [optional] |
| 330 | */ |
| 331 | start (cb) { |
| 332 | let retries = 0 |
| 333 | this._rpc = this.startRPC() |
| 334 | this.opts.ROOT_URL = cst.KEYMETRICS_ROOT_URL |
| 335 | |
| 336 | const verifyEndpointCallback = (err, result) => { |
| 337 | if (err) { |
| 338 | log('Error while trying to retrieve endpoints : ' + (err.message || err)) |
| 339 | if (retries++ < 30 && process.env.NODE_ENV !== 'test') { |
| 340 | log('Retrying to retrieve endpoints...') |
| 341 | return setTimeout(_ => { |
| 342 | return this._verifyEndpoint(verifyEndpointCallback) |
| 343 | }, 200 * retries) |
| 344 | } |
| 345 | this.sendToParent({ error: true, msg: err.message || err }) |
| 346 | return this.exit(new Error('Error retrieving endpoints')) |
| 347 | } |
| 348 | if (result === false) { |
| 349 | log('False returned while trying to retrieve endpoints') |
| 350 | return this.exit(new Error('Error retrieving endpoints')) |
| 351 | } |
| 352 | |
| 353 | // send data over IPC for CLI feedback |
| 354 | this.sendToParent({ |
| 355 | error: false, |
| 356 | km_data: this.km_data, |
| 357 | online: true, |
| 358 | pid: process.pid, |
| 359 | machine_name: this.opts.MACHINE_NAME, |
| 360 | public_key: this.opts.PUBLIC_KEY, |
| 361 | secret_key: this.opts.SECRET_KEY, |
| 362 | reverse_interaction: this.opts.REVERSE_INTERACT |
| 363 | }) |
| 364 | |
| 365 | if (result && typeof result === 'object' && |
| 366 | result.error === true && result.active === false) { |
| 367 | log(`Error when connecting: ${result.msg}`) |
| 368 | return this.exit(new Error(`Error when connecting: ${result.msg}`)) |
| 369 | } |
| 370 | |
| 371 | // start workers |
| 372 | this._workerEndpoint = setInterval(this._verifyEndpoint.bind(this, (err, result) => { |
| 373 | if (err) return |
| 374 | // We need to exit agent if bucket is disabled (trialing) |
| 375 | if (result && typeof result === 'object' && result.error === true && result.active === false) { |
| 376 | log(`Error when connecting: ${result.msg}, disconnecting transporters`) |
| 377 | return this.transport.disconnect() |
| 378 | } |
| 379 | }), 60000) |
| 380 | // start interactors |
| 381 | this.watchDog = WatchDog |
| 382 | |
| 383 | setTimeout(() => { |
| 384 | log('>> PM2 Watchdog started') |
| 385 | this.watchDog.start({ |
| 386 | pm2_binary_path: this.opts.PM2_BINARY_PATH, |
| 387 | conf: { |
| 388 | ipm2: this.getPM2Client() |
no test coverage detected