mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
fix(api): pm2 start script & limit auto restarts (#1040)
* fix(api): limit auto restarts to 10 so persistent errors (e.g. during server boot) don't cause an infinite loop that's difficult for users to see * fix(api): invoke js directly from pm2 instead of npm script npm script wraps it in a child process, so we lose ipc. * fix(api): update api key service test for ensureDir change * chore: increase max_restart threshold to 10s per cycle
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
"apps": [
|
||||
{
|
||||
"name": "unraid-api",
|
||||
"script": "npm",
|
||||
"args": "start",
|
||||
"script": "./dist/main.js",
|
||||
"cwd": "/usr/local/unraid-api",
|
||||
"log": "/var/log/unraid-api/unraid-api.log",
|
||||
"exec_mode": "fork",
|
||||
"wait_ready": true,
|
||||
"listen_timeout": 30000,
|
||||
"max_restarts": 10,
|
||||
"min_uptime": 10000,
|
||||
"ignore_watch": [
|
||||
"node_modules",
|
||||
"src",
|
||||
@@ -17,4 +18,4 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -91,7 +91,6 @@ describe('ApiKeyService', () => {
|
||||
vi.mocked(ensureDir).mockResolvedValue();
|
||||
|
||||
apiKeyService = new ApiKeyService();
|
||||
await apiKeyService.initialize();
|
||||
|
||||
vi.spyOn(apiKeyService as any, 'generateApiKey').mockReturnValue('test-api-key');
|
||||
vi.mock('uuid', () => ({
|
||||
@@ -113,12 +112,8 @@ describe('ApiKeyService', () => {
|
||||
|
||||
describe('initialization', () => {
|
||||
it('should ensure directory exists', async () => {
|
||||
vi.mocked(ensureDir).mockResolvedValue();
|
||||
const service = new ApiKeyService();
|
||||
|
||||
await service.initialize();
|
||||
|
||||
expect(ensureDir).toHaveBeenCalledWith(mockBasePath);
|
||||
expect(ensureDirSync).toHaveBeenCalledWith(mockBasePath);
|
||||
});
|
||||
|
||||
it('should return correct paths', async () => {
|
||||
|
||||
@@ -54,6 +54,8 @@ export async function bootstrapNestServer(): Promise<NestFastifyApplication> {
|
||||
// See https://pm2.keymetrics.io/docs/usage/signals-clean-restart/
|
||||
if (process.send) {
|
||||
process.send('ready');
|
||||
} else {
|
||||
console.log('Warning: process.send is unavailable. This will affect IPC communication with PM2.');
|
||||
}
|
||||
apiLogger.info('Nest Server is now listening');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user