From 46fb01d336c746fef8551da5f47dbbb72c5a5e77 Mon Sep 17 00:00:00 2001 From: sneakers-the-rat Date: Tue, 8 Aug 2023 17:44:24 -0700 Subject: [PATCH] close server when sigterm --- server/src/app.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/server/src/app.ts b/server/src/app.ts index 8020e9b..a6cf8eb 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -47,22 +47,29 @@ AppDataSource.initialize() }); const port = config.get('port'); - app.listen(port); + const server = app.listen(port); logger.info(`Server started on port: ${port}`) await MatterbridgeManager.spawnAll(); let proclist = await MatterbridgeManager.processes; logger.info('Spawned group processes: %s', proclist); + + // Register signal handlers + process.on('SIGTERM', () => { + logger.debug('killing matterbridge from SIGTERM') + killMatterbridge() + server.close() + process.exit(0) + }) + process.on('exit', () => { + logger.debug('killing matterbridge from exit event') + killMatterbridge() + server.close() + }) + + }) // Kill matterbridge processes on app exit. -process.on('SIGTERM', () => { - logger.debug('killing matterbridge from SIGTERM') - killMatterbridge() -}) -process.on('exit', () => { - logger.debug('killing matterbridge from exit event') - killMatterbridge() -})