Skip to content

Instantly share code, notes, and snippets.

@ivandez
Created March 17, 2024 16:21
Show Gist options
  • Save ivandez/49d6122b211e0680f6d8843f52af9056 to your computer and use it in GitHub Desktop.
Save ivandez/49d6122b211e0680f6d8843f52af9056 to your computer and use it in GitHub Desktop.
How to graceful shutdown an express docker app
// source: https://stackoverflow.com/questions/78121173/how-to-graceful-shutdown-an-express-docker-app
// Option 1
process.on("SIGTERM", function(code_signal_error){
process.exit(0) //or whatever you want
})
// Option 2
[`exit`, `SIGQUIT`, `SIGINT`, `SIGUSR1`, `SIGUSR2`, `uncaughtException`, `SIGTERM`].forEach(function(evt){
process.on(evt, this);
}, once(
function(code_signal_error){
//decide what to do here. Terminate workers etc.
//do not forget to call process.exit(0) or whatever value makes sense to you.
}
));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment