fix: move process.exit to child

This commit is contained in:
Alexis
2021-09-10 16:43:21 +09:30
parent 52c51ecd2a
commit c66f93bda2

View File

@@ -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();