Skip to content

Commit

Permalink
Unitech#3085 ignore default commander.js value on restart/reload
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Aug 11, 2017
1 parent cc874b1 commit 4abacdb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
19 changes: 15 additions & 4 deletions lib/API.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ API.prototype.reload = function(process_name, opts, cb) {
if (opts && !opts.updateEnv)
Common.printOut(IMMUTABLE_MSG);


that._operate('reloadProcessId', process_name, opts, function(err, apps) {
Common.unlockReload();

Expand Down Expand Up @@ -1214,7 +1213,6 @@ API.prototype._operate = function(action_name, process_name, envs, cb) {
var ret = [];

// Make sure all options exist

if (!envs)
envs = {};

Expand Down Expand Up @@ -1443,11 +1441,24 @@ API.prototype._handleAttributeUpdate = function(opts) {

delete appConf.exec_mode;

if(util.isArray(appConf.watch) && appConf.watch.length === 0) {
if(!~opts.rawArgs.indexOf('--watch'))
if (util.isArray(appConf.watch) && appConf.watch.length === 0) {
if (!~opts.rawArgs.indexOf('--watch'))
delete appConf.watch
}

// Force deletion of defaults values set by commander
// to avoid overriding specified configuration by user
if (appConf.treekill === true)
delete appConf.treekill;
if (appConf.pmx === true)
delete appConf.pmx;
if (appConf.vizion === true)
delete appConf.vizion;
if (appConf.automation === true)
delete appConf.automation;
if (appConf.autorestart === true)
delete appConf.autorestart;

return appConf;
};

Expand Down
31 changes: 31 additions & 0 deletions test/programmatic/api.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,37 @@ describe('API checks', function() {
});
});

describe('Should keep environment variables', function() {
it('should start app with treekill', function(done) {
PM2.start({
script : './../fixtures/child.js',
instances : 1,
treekill : false,
name : 'http-test'
}, function(err) {
should(err).be.null();
PM2.list(function(err, list) {
should(err).be.null();
should(list.length).eql(1);
should(list[0].pm2_env.treekill).be.false;
done();
});
});
});

it('should restart app and treekill still at false', function(done) {
PM2.restart('http-test', function() {
PM2.list(function(err, list) {
should(err).be.null();
should(list.length).eql(1);
should(list[0].pm2_env.treekill).be.false;
done();
});
});
});

});

describe('Issue #2337', function() {
before(function(done) {
PM2.delete('all', function() { done() });
Expand Down

0 comments on commit 4abacdb

Please sign in to comment.