const { buildApp } = require("./app"); async function main() { const app = await buildApp(); const { host, port } = app.config; await app.listen({ host, port }); let shuttingDown = false; const shutdown = async (signal) => { if (shuttingDown) return; shuttingDown = true; app.log.info({ signal }, "Graceful shutdown start"); const timeoutMs = 10_000; const forceTimer = setTimeout(() => { app.log.error({ timeoutMs }, "Graceful shutdown timeout, force exit"); process.exit(1); }, timeoutMs); forceTimer.unref?.(); try { await app.close(); app.log.info("Graceful shutdown completed"); process.exit(0); } catch (error) { app.log.error({ err: error }, "Graceful shutdown failed"); process.exit(1); } }; process.on("SIGTERM", () => shutdown("SIGTERM")); process.on("SIGINT", () => shutdown("SIGINT")); } main().catch((err) => { // eslint-disable-next-line no-console console.error(err); process.exit(1); });