Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Gracefully handle exit #549

Open
nahtnam opened this issue Feb 14, 2021 · 0 comments
Open

Gracefully handle exit #549

nahtnam opened this issue Feb 14, 2021 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@nahtnam
Copy link
Contributor

nahtnam commented Feb 14, 2021

async function closeGracefully(signal) {
   console.log(`*^!@4=> Received signal to terminate: ${signal}`)
 
   await fastify.close()
   // await db.close() if we have a db connection in this app
   // await other things we should cleanup nicely
   process.exit()
}
process.on('SIGINT', closeGracefully)
process.on('SIGTERM', closeGracefully)

pulled from https://snyk.io/blog/10-best-practices-to-containerize-nodejs-web-applications-with-docker/

@nahtnam nahtnam added enhancement New feature or request good first issue Good for newcomers labels Feb 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant