From 2ecdb99052f39d89af21bbe7ad3f80b83bb1eaa9 Mon Sep 17 00:00:00 2001 From: Eli Bosley Date: Thu, 4 Sep 2025 20:03:28 -0400 Subject: [PATCH] fix: custom path detection to fix setup issues (#1664) ## Summary by CodeRabbit - Bug Fixes - Improved reliability of background command execution by ensuring common system binary paths are available, reducing PATH-related errors. - Aligned environment handling for spawned processes with typical shell behavior to prevent intermittent failures across different environments. --- api/src/unraid-api/cli/pm2.service.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/api/src/unraid-api/cli/pm2.service.ts b/api/src/unraid-api/cli/pm2.service.ts index e80b44949..95355911b 100644 --- a/api/src/unraid-api/cli/pm2.service.ts +++ b/api/src/unraid-api/cli/pm2.service.ts @@ -42,8 +42,22 @@ export class PM2Service { async run(context: CmdContext, ...args: string[]) { const { tag, raw, ...execOptions } = context; - execOptions.extendEnv ??= false; + // Default to true to match execa's default behavior + execOptions.extendEnv ??= true; execOptions.shell ??= 'bash'; + + // Ensure /usr/local/bin is in PATH for Node.js + const currentPath = execOptions.env?.PATH || process.env.PATH || '/usr/bin:/bin:/usr/sbin:/sbin'; + const needsPathUpdate = !currentPath.includes('/usr/local/bin'); + const finalPath = needsPathUpdate ? `/usr/local/bin:${currentPath}` : currentPath; + + // Only modify PATH if needed, regardless of extendEnv setting + if (needsPathUpdate) { + execOptions.env = { + ...execOptions.env, + PATH: finalPath, + }; + } const runCommand = () => execa(PM2_PATH, [...args], execOptions satisfies Options); if (raw) { return runCommand();