mirror of
https://github.com/unraid/api.git
synced 2026-05-18 06:29:40 -05:00
fix: use exitCode to allow streams to drain on exit
This commit is contained in:
+1
-1
@@ -273,7 +273,7 @@ async function main() {
|
||||
if (!command) {
|
||||
if (mainOptions.version) {
|
||||
await commands.version();
|
||||
process.exit();
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// Run help command
|
||||
|
||||
@@ -12,7 +12,8 @@ import { coreLogger } from '../../log';
|
||||
export const exitApp = (error?: Error, exitCode?: number) => {
|
||||
if (!error) {
|
||||
// Kill application immediately
|
||||
process.exit(exitCode ?? 0);
|
||||
process.exitCode = exitCode ?? 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Allow non-fatal errors to throw but keep the app running
|
||||
@@ -32,6 +33,6 @@ export const exitApp = (error?: Error, exitCode?: number) => {
|
||||
coreLogger.error(error);
|
||||
|
||||
// Kill application
|
||||
process.exit(exitCode);
|
||||
process.exitCode = exitCode;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,6 +23,6 @@ export const globalErrorHandler = (error: Error) => {
|
||||
console.error(error);
|
||||
|
||||
// Kill application
|
||||
process.exit(1);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
};
|
||||
|
||||
+5
-2
@@ -8,7 +8,7 @@ import am from 'am';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import exitHook from 'async-exit-hook';
|
||||
import getServerAddress from 'get-server-address';
|
||||
import { core, states, coreLogger, log, apiManager, apiManagerLogger } from './core';
|
||||
import { core, states, coreLogger, log, apiManager, apiManagerLogger, logger } from './core';
|
||||
import { server } from './server';
|
||||
import { mothership } from './mothership/subscribe-to-servers';
|
||||
import { startInternal, sockets } from './mothership';
|
||||
@@ -158,6 +158,9 @@ am(async () => {
|
||||
log.error(error);
|
||||
});
|
||||
}, async (error: NodeJS.ErrnoException) => {
|
||||
// Log error to syslog
|
||||
log.error(error);
|
||||
|
||||
// Send error to server for debugging
|
||||
Sentry.captureException(error);
|
||||
|
||||
@@ -172,6 +175,6 @@ am(async () => {
|
||||
await Sentry.flush(5000);
|
||||
|
||||
// Kill application
|
||||
process.exit(1);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user