Created
August 7, 2020 19:52
-
-
Save cvan/4a53a992c283e5944c8b6987e301591f to your computer and use it in GitHub Desktop.
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
if (process.env.NODE_ENV === 'development') { | |
// This helps for nodemon to not be prematurely killed. | |
// See nodemon's docs: https://github.com/remy/nodemon/blob/master/README.md#controlling-shutdown-of-your-script | |
// Adapted from source: https://www.benjiegillam.com/2011/08/node-js-clean-restart-and-faster-development-with-nodemon/ | |
const gracefulShutdown = cb => { | |
setTimeout(() => { | |
process.exit(0); | |
cb(); | |
}, 5000); | |
}; | |
// Handle SIGUSR2, but only once. | |
process.once('SIGUSR2', () => { | |
// Graceful shutdown. | |
gracefulShutdown(() => { | |
// Kill ourself with the SIGUSR2 signal again. | |
process.kill(process.pid, 'SIGUSR2'); | |
}); | |
}); | |
process.on('SIGTERM', () => { | |
// https://expressjs.com/en/advanced/healthcheck-graceful-shutdown.html | |
app.close(() => { | |
// eslint-disable-next-line no-console | |
console.log('Server closing. Process terminated.'); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment