From c66f93bda2016faf5ae35ad3b05d508c4157afe3 Mon Sep 17 00:00:00 2001 From: Alexis Date: Fri, 10 Sep 2021 16:43:21 +0930 Subject: [PATCH] fix: move process.exit to child --- app/cli.ts | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/app/cli.ts b/app/cli.ts index 293fd8005..cec46841a 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -109,6 +109,17 @@ const commands = { if ('_DAEMONIZE_PROCESS' in process.env) { // In the child, clean up the tracking environment variable delete process.env._DAEMONIZE_PROCESS; + + // Log when the API exits cleanly + process.on('exit', code => { + logger.info('👋 Farewell. UNRAID API shutting down with code %s!', code); + }); + + // Log when the API crashes + process.on('uncaughtException', (error, origin) => { + logger.log(`Caught exception: ${error.message}\nException origin: ${origin}`); + logger.log('⚠️ UNRAID API crashed'); + }); } else { logger.debug('Daemonizing process.'); @@ -123,26 +134,6 @@ const commands = { detached: true }); - // This should log when the app closes, not the cli - let deaths = 0; - process.on('beforeExit', code => { - // Only log when the child dies - if (deaths === 0) { - deaths++; - return; - } - - if (code === 0) { - logger.info('👋 Farewell. UNRAID API shutting down!'); - } - }); - - // This should log when the app crashes, not the cli - process.on('uncaughtException', (error, origin) => { - logger.log(`Caught exception: ${error.message}\nException origin: ${origin}`); - logger.log('⚠️ UNRAID API crashed'); - }); - // Convert process into daemon child.unref();