mirror of
https://github.com/unraid/api.git
synced 2026-01-07 09:10:05 -06:00
fix: move process.exit to child
This commit is contained in:
31
app/cli.ts
31
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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user