Created
March 17, 2024 16:21
-
-
Save ivandez/49d6122b211e0680f6d8843f52af9056 to your computer and use it in GitHub Desktop.
How to graceful shutdown an express docker app
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
// 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