cleanly shutdown

wait for webserver to stop accepting connections
destroy current connections
wait for db connection to close
This commit is contained in:
Barış Soner Uşaklı
2018-03-22 16:36:18 -04:00
parent 1d42d1a6d2
commit 77d47b31fb
4 changed files with 43 additions and 10 deletions

View File

@@ -153,11 +153,21 @@ function restart() {
function shutdown(code) {
winston.info('[app] Shutdown (SIGTERM/SIGINT) Initialised.');
require('./database').close();
winston.info('[app] Database connection closed.');
require('./webserver').server.close();
winston.info('[app] Web server closed to connections.');
winston.info('[app] Shutdown complete.');
process.exit(code || 0);
async.waterfall([
function (next) {
require('./webserver').destroy(next);
},
function (next) {
winston.info('[app] Web server closed to connections.');
require('./database').close(next);
},
], function (err) {
if (err) {
winston.error(err);
return process.exit(code || 0);
}
winston.info('[app] Database connection closed.');
winston.info('[app] Shutdown complete.');
process.exit(code || 0);
});
}