mirror of
https://github.com/unraid/api.git
synced 2026-01-07 09:10:05 -06:00
fix: narrow api exec command
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
"src",
|
||||
".env.*"
|
||||
],
|
||||
"exec": "node ./dist/main.js",
|
||||
"exec": "node $UNRAID_API_SERVER_ENTRYPOINT",
|
||||
"signal": "SIGTERM",
|
||||
"ext": "js,json",
|
||||
"restartable": "rs",
|
||||
|
||||
@@ -110,6 +110,7 @@ export const NODEMON_PATH = join(UNRAID_API_ROOT, 'node_modules', 'nodemon', 'bi
|
||||
export const NODEMON_CONFIG_PATH = join(UNRAID_API_ROOT, 'nodemon.json');
|
||||
export const NODEMON_PID_PATH = process.env.NODEMON_PID_PATH ?? '/var/run/unraid-api/nodemon.pid';
|
||||
export const UNRAID_API_CWD = process.env.UNRAID_API_CWD ?? UNRAID_API_ROOT;
|
||||
export const UNRAID_API_SERVER_ENTRYPOINT = join(UNRAID_API_CWD, 'dist', 'main.js');
|
||||
|
||||
export const PATHS_CONFIG_MODULES =
|
||||
process.env.PATHS_CONFIG_MODULES ?? '/boot/config/plugins/dynamix.my.servers/configs';
|
||||
|
||||
@@ -83,6 +83,7 @@ describe('NodemonService (real nodemon)', () => {
|
||||
PATHS_LOGS_FILE: appLogPath,
|
||||
PATHS_NODEMON_LOG_FILE: nodemonLogPath,
|
||||
UNRAID_API_CWD: workdir,
|
||||
UNRAID_API_SERVER_ENTRYPOINT: join(workdir, 'app.js'),
|
||||
}));
|
||||
|
||||
const { NodemonService } = await import('./nodemon.service.js');
|
||||
|
||||
@@ -80,6 +80,7 @@ vi.mock('@app/environment.js', () => ({
|
||||
PATHS_LOGS_FILE: '/var/log/graphql-api.log',
|
||||
PATHS_NODEMON_LOG_FILE: '/var/log/unraid-api/nodemon.log',
|
||||
UNRAID_API_CWD: '/usr/local/unraid-api',
|
||||
UNRAID_API_SERVER_ENTRYPOINT: '/usr/local/unraid-api/dist/main.js',
|
||||
}));
|
||||
|
||||
describe('NodemonService', () => {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { openSync, writeSync } from 'node:fs';
|
||||
import { appendFile, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { dirname } from 'node:path';
|
||||
|
||||
import { execa } from 'execa';
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
PATHS_LOGS_FILE,
|
||||
PATHS_NODEMON_LOG_FILE,
|
||||
UNRAID_API_CWD,
|
||||
UNRAID_API_SERVER_ENTRYPOINT,
|
||||
} from '@app/environment.js';
|
||||
import { LogService } from '@app/unraid-api/cli/log.service.js';
|
||||
|
||||
@@ -147,9 +148,6 @@ export class NodemonService {
|
||||
|
||||
private async findDirectMainPids(): Promise<number[]> {
|
||||
try {
|
||||
// Note: ps may show relative path "node ./dist/main.js" instead of absolute path
|
||||
// So we check for both patterns: the absolute path and the relative "dist/main.js"
|
||||
const mainPath = join(UNRAID_API_CWD, 'dist', 'main.js');
|
||||
const { stdout } = await execa('ps', ['-eo', 'pid,args']);
|
||||
return stdout
|
||||
.split('\n')
|
||||
@@ -157,7 +155,7 @@ export class NodemonService {
|
||||
.map((line) => line.match(/^(\d+)\s+(.*)$/))
|
||||
.filter((match): match is RegExpMatchArray => Boolean(match))
|
||||
.map(([, pid, cmd]) => ({ pid: Number.parseInt(pid, 10), cmd }))
|
||||
.filter(({ cmd }) => cmd.includes(mainPath) || /node.*dist\/main\.js/.test(cmd))
|
||||
.filter(({ cmd }) => cmd.includes(UNRAID_API_SERVER_ENTRYPOINT))
|
||||
.map(({ pid }) => pid)
|
||||
.filter((pid) => Number.isInteger(pid));
|
||||
} catch {
|
||||
@@ -340,6 +338,7 @@ export class NodemonService {
|
||||
NODEMON_CONFIG_PATH,
|
||||
NODEMON_PID_PATH,
|
||||
UNRAID_API_CWD,
|
||||
UNRAID_API_SERVER_ENTRYPOINT,
|
||||
...overrides,
|
||||
} as Record<string, string>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user