Skip to content

Commit

Permalink
#42
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed May 10, 2018
1 parent e65033b commit fabe35f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/InteractorClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,20 @@ module.exports = class InteractorDaemonizer {
if (err || !conf) return cb(err || new Error('Cant retrieve configuration'))

if (!process.env.PM2_SILENT) {
console.log(chalk.cyan('[Keymetrics.io]') + ' Using (Public key: %s) (Private key: %s)', conf.public_key, conf.secret_key)
console.log(chalk.cyan('[PM2 Agent]') + ' Using (Public key: %s) (Private key: %s)', conf.public_key, conf.secret_key)
}
return this.launchOrAttach(cst, conf, cb)
})
}

static rescueRestart(conf, cb) {
this.getOrSetConf(conf, null, (err, infos) => {
if (err || !infos) return cb(err)
console.log(chalk.cyan('[PM2 Agent]') + ' Using (Public key: %s) (Private key: %s) (Info node: %s)', infos.public_key, infos.secret_key, infos.info_node)
this.daemonize(conf, infos, cb)
})
}

/**
* Retrieve configuration used by the Interaction Daemon
* @param {Object} cst global constants
Expand Down
21 changes: 19 additions & 2 deletions src/InteractorDaemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,29 @@ const InteractorDaemon = module.exports = class InteractorDaemon {
// otherwise we just required it to use a function
if (require.main === module) {
const d = domain.create()

d.on('error', function (err) {
console.error(err)
console.error('------------------ FATAL EXCEPTION ---------------')
console.error(new Date())
console.error(err.message)
console.error(err.stack)
console.log('Re initiating Agent')
var KMDaemon = require('./InteractorClient');

KMDaemon.rescueRestart(cst, function(err, dt) {
if (err) {
console.error('[PM2 Agent] Failed to rescue agent, error:');
console.error(err.message || err);
process.exit(1);
}
console.log('[PM2 Agent] Rescued.');
process.exit(0);
})
})
d.run(_ => {
process.title = 'PM2: KM Agent (' + process.env.PM2_HOME + ')'
log('[Keymetrics.io] Launching agent')

log('[PM2 Agent] Launching agent')
new InteractorDaemon().start()
})
}

0 comments on commit fabe35f

Please sign in to comment.