mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
feat: swap to async exit hook
This commit is contained in:
@@ -9,7 +9,7 @@ import https from 'https';
|
||||
|
||||
import type { RawServerDefault } from 'fastify';
|
||||
import CacheableLookup from 'cacheable-lookup';
|
||||
import exitHook from 'exit-hook';
|
||||
import { asyncExitHook, gracefulExit } from 'exit-hook';
|
||||
import { WebSocket } from 'ws';
|
||||
|
||||
import { logger } from '@app/core/log';
|
||||
@@ -91,17 +91,19 @@ try {
|
||||
// Start webserver
|
||||
server = await bootstrapNestServer();
|
||||
|
||||
// On process exit stop HTTP server
|
||||
exitHook(async (signal) => {
|
||||
console.log('exithook', signal);
|
||||
await server?.close?.();
|
||||
// If port is unix socket, delete socket before exiting
|
||||
unlinkUnixPort();
|
||||
asyncExitHook(
|
||||
async (signal) => {
|
||||
console.log('exithook', signal);
|
||||
await server?.close?.();
|
||||
// If port is unix socket, delete socket before exiting
|
||||
unlinkUnixPort();
|
||||
|
||||
shutdownApiEvent();
|
||||
shutdownApiEvent();
|
||||
|
||||
process.exit(0);
|
||||
});
|
||||
gracefulExit();
|
||||
},
|
||||
{ wait: 9999 }
|
||||
);
|
||||
// Start a loop to run the app
|
||||
await new Promise(() => {});
|
||||
} catch (error: unknown) {
|
||||
@@ -115,5 +117,5 @@ try {
|
||||
}
|
||||
shutdownApiEvent();
|
||||
// Kill application
|
||||
process.exit(1);
|
||||
gracefulExit(1);
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { beforeAll, expect, test } from 'vitest';
|
||||
|
||||
import { store } from '@app/store';
|
||||
import { loadConfigFile } from '@app/store/modules/config';
|
||||
import { anonymiseOrigins } from '@app/unraid-api/cli/report.command';
|
||||
|
||||
beforeAll(async () => {
|
||||
// Load cfg into store
|
||||
await store.dispatch(loadConfigFile());
|
||||
});
|
||||
|
||||
test('anonymise origins removes .sock origins', async () => {
|
||||
expect(anonymiseOrigins(['/var/run/test.sock'])).toEqual([]);
|
||||
});
|
||||
|
||||
test('anonymise origins hides WAN port', async () => {
|
||||
expect(anonymiseOrigins(['https://domain.tld:8443'])).toEqual(['https://domain.tld:WANPORT']);
|
||||
});
|
||||
Reference in New Issue
Block a user