Created
September 7, 2016 08:32
-
-
Save duythinht/06e5315eca0f049355093047a13dbe0b to your computer and use it in GitHub Desktop.
Restart on demand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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