* Ping the Interactor to see if its online * @param {Object} opts global constants * @param {String} opts.INTERACTOR_RPC_PORT path used to connect to the interactor * @param {Function} cb invoked with
(opts, cb)
| 28 | * @param {Function} cb invoked with <err, result> |
| 29 | */ |
| 30 | static ping (opts, cb) { |
| 31 | if (typeof cb !== 'function') { |
| 32 | throw new Error('Missing parameters') |
| 33 | } else if (typeof opts !== 'object' || !opts || !opts.INTERACTOR_RPC_PORT) { |
| 34 | return cb(new Error('Missing parameters')) |
| 35 | } |
| 36 | const req = axon.socket('req') |
| 37 | const client = new rpc.Client(req) |
| 38 | |
| 39 | log('[PING INTERACTOR] Trying to connect to Interactor daemon') |
| 40 | |
| 41 | client.sock.once('reconnect attempt', _ => { |
| 42 | client.sock.close() |
| 43 | log('Interactor Daemon not launched') |
| 44 | return cb(null, false) |
| 45 | }) |
| 46 | |
| 47 | client.sock.once('connect', _ => { |
| 48 | client.sock.once('close', _ => { |
| 49 | return cb(null, true) |
| 50 | }) |
| 51 | client.sock.close() |
| 52 | log('Interactor Daemon alive') |
| 53 | }) |
| 54 | |
| 55 | client.sock.once('error', (e) => { |
| 56 | if (e.code === 'EACCES') { |
| 57 | fs.stat(opts.INTERACTOR_RPC_PORT, (e, stats) => { |
| 58 | if (stats.uid === 0) { |
| 59 | console.error('Permission denied, activate current user') |
| 60 | return process.exit(1) |
| 61 | } |
| 62 | }) |
| 63 | } else { |
| 64 | console.error('unexpected error') |
| 65 | console.error(e) |
| 66 | } |
| 67 | }) |
| 68 | |
| 69 | req.connect(opts.INTERACTOR_RPC_PORT) |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Try to kill the interactor daemon via RPC |
no test coverage detected