Graceful Shutdown
Introduction
Graceful shutdown means that the OS (operating system) can safely shut down its processes and close all connections, however long that takes. This helps to prevent accidental data loss or other unexpected problems if the shutdown is performed intentionally by the user.
Configurations
Athenna already comes with graceful shutdown configured by default using the gracefulShutdown
object in config/app.js
file. In this
object you can configure all SIGNALS
that Node.js process will listen for in your application. Athenna comes with SIGINT
and SIGTERM
already configured by default:
import { ProviderHelper } from '@athenna/core'
gracefulShutdown: {
SIGINT: async () => {
await ProviderHelper.shutdownAll(false)
process.exit()
},
SIGTERM: async signal => {
await ProviderHelper.shutdownAll()
process.kill(process.pid, signal)
},
},
It's imperative that you always call the ProviderHelper.shutdownAll()
method in your signals configurations. This method is who will
call the shutdown
method of Athenna providers.
Disabling graceful shutdown
To disable the graceful shutdown of some SIGNAL you can just remove it from gracefulShutdown
object in config/app.js
:
gracefulShutdown: {}