mirror of
https://github.com/unraid/api.git
synced 2025-12-30 21:19:49 -06:00
fix: custom path detection to fix setup issues (#1664)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user