mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
(instance_var) allow to overide the key NODE_APP_INSTANCE #2045
This commit is contained in:
parent
35945e82d0
commit
d43e44f8b2
@ -185,5 +185,9 @@
|
||||
},
|
||||
"increment_var": {
|
||||
"type": "string"
|
||||
},
|
||||
"instance_var": {
|
||||
"type": "string",
|
||||
"default" : "NODE_INSTANCE_APP"
|
||||
}
|
||||
}
|
||||
|
||||
@ -457,19 +457,22 @@ God.finalizeProcedure = function finalizeProcedure(proc) {
|
||||
* @param {Function} cb invoked with <err, env>
|
||||
*/
|
||||
God.injectVariables = function injectVariables (env, cb) {
|
||||
// allow to override the key of NODE_APP_INSTANCE if wanted
|
||||
var instanceKey = process.env.PM2_PROCESS_INSTANCE_VAR || env.instance_var;
|
||||
|
||||
// we need to find the last NODE_APP_INSTANCE used
|
||||
var lastInstance = Object.keys(God.clusters_db)
|
||||
.map(function (procId) {
|
||||
return God.clusters_db[procId];
|
||||
}).filter(function (proc) {
|
||||
return proc.pm2_env.name === env.name &&
|
||||
typeof proc.pm2_env.NODE_APP_INSTANCE !== 'undefined';
|
||||
typeof proc.pm2_env[instanceKey] !== 'undefined';
|
||||
}).map(function (proc) {
|
||||
return proc.pm2_env.NODE_APP_INSTANCE;
|
||||
return proc.pm2_env[instanceKey];
|
||||
}).sort(function (a, b) {
|
||||
return b - a;
|
||||
})[0];
|
||||
env.NODE_APP_INSTANCE = typeof lastInstance === 'undefined' ? 0 : lastInstance + 1;
|
||||
env[instanceKey] = typeof lastInstance === 'undefined' ? 0 : lastInstance + 1;
|
||||
|
||||
// if using increment_var, we need to increment it
|
||||
if (env.increment_var) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user