Created
October 15, 2015 04:12
-
-
Save neurotech/282f634a508773d16c9e to your computer and use it in GitHub Desktop.
Graceful shutdown in node
This file contains hidden or 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
var shutDown = function() { | |
logger.info('Gracefully shutting down.'); | |
process.nextTick(function() { | |
logger.info('Shutting down Express.'); | |
server.close(); | |
}); | |
process.nextTick(function() { | |
logger.info('Shutting down database connection.'); | |
db.close(); | |
}); | |
setTimeout(function() { | |
logger.error("Couldn\'t shut down gracefully. Forcefully shutting down!"); | |
process.exit(); | |
}, 15*1000); | |
}; | |
process.on("SIGTERM", shutDown); | |
process.on("SIGINT", shutDown); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment