Skip to content

Commit 8246151

Browse files
authored
Merge pull request #19 from aliyun-node/fix_env_check_when_start_by_pm2_with_config
fix env check when started by pm2 with config
2 parents f625827 + 1809599 commit 8246151

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

get_process_env.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ function getProcessEnv(pid) {
4545
const lines = output.split('\u0000');
4646

4747
var env = {ENABLE_NODE_LOG: '', NODE_LOG_DIR: '/tmp'};
48+
var pm2_env = {};
4849

4950
for (var i = 0; i < lines.length; i++) {
5051
const line = lines[i];
@@ -55,8 +56,18 @@ function getProcessEnv(pid) {
5556
if (line.startsWith('NODE_LOG_DIR')) {
5657
env.NODE_LOG_DIR = line.split('=')[1];
5758
}
59+
60+
if (line.startsWith('pm2_env=')) {
61+
try {
62+
pm2_env = JSON.parse(line.substr('pm2_env='.length));
63+
} catch (e) {
64+
}
65+
}
5866
}
5967

68+
env.NODE_LOG_DIR = env.NODE_LOG_DIR || pm2_env.NODE_LOG_DIR;
69+
env.ENABLE_NODE_LOG = env.ENABLE_NODE_LOG || pm2_env.ENABLE_NODE_LOG;
70+
6071
if (!env.NODE_LOG_DIR.endsWith('/')) {
6172
env.NODE_LOG_DIR += '/';
6273
}

0 commit comments

Comments
 (0)