Skip to content

Instantly share code, notes, and snippets.

@duythinht
Created September 7, 2016 08:32
Show Gist options
  • Save duythinht/06e5315eca0f049355093047a13dbe0b to your computer and use it in GitHub Desktop.
Save duythinht/06e5315eca0f049355093047a13dbe0b to your computer and use it in GitHub Desktop.
Restart on demand
const cluster = require('cluster')
var logger = require('log4js').getLogger()
var locator = require('consul-locator')
locator.use({host: '10.60.3.231'})
logger.info('Start workers')
function startWorker(name) {
cluster.setupMaster({
exec: `./workers/${name}.js`
})
cluster.fork().on('disconnect', () => {
logger.info(name, 'worker is disconnect, restart in 5s')
setTimeout(() => startWorker(name), 5000)
})
}
startWorker('restart.in.5s')
//restart.in.5s
//TODO: blah blah
console.log('// DO stuff here')
process.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment