From 1f53a6f95722561224d553db3ebf85ac9828a8f3 Mon Sep 17 00:00:00 2001 From: Harlen Tan Date: Thu, 31 Jan 2019 18:16:26 +0800 Subject: [PATCH] fix spawn ps ENOENT #3879 The `process.env.PATH` is not set in the PATH of plist. And the pm2 will throw command ENOENT error because of it. --- lib/API/Startup.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/API/Startup.js b/lib/API/Startup.js index 23103753..20300ca4 100644 --- a/lib/API/Startup.js +++ b/lib/API/Startup.js @@ -11,6 +11,7 @@ var eachLimit = require('async/eachLimit'); var exec = require('child_process').exec; var Common = require('../Common.js'); var cst = require('../../constants.js'); +var util = require('util'); module.exports = function(CLI) { /** @@ -307,8 +308,11 @@ module.exports = function(CLI) { /** * 4# Replace template variable value */ + var envPath = new RegExp(path.dirname(process.execPath)).test(process.env.PATH) + ? process.env.PATH + : util.format('%s:%s', process.env.PATH || '', path.dirname(process.execPath)); template = template.replace(/%PM2_PATH%/g, process.mainModule.filename) - .replace(/%NODE_PATH%/g, path.dirname(process.execPath)) + .replace(/%NODE_PATH%/g, envPath) .replace(/%USER%/g, user) .replace(/%HOME_PATH%/g, opts.hp ? path.resolve(opts.hp, '.pm2') : cst.PM2_ROOT_PATH) .replace(/%SERVICE_NAME%/g, service_name);