Skip to content

Commit e2aa872

Browse files
committed
-i <instances> default to exec_mode fork if not a node app + add test + remove unused test
1 parent 6d85f4c commit e2aa872

File tree

9 files changed

+108
-116
lines changed

9 files changed

+108
-116
lines changed

lib/API.js

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -646,23 +646,20 @@ class API {
646646
}
647647
var that = this;
648648

649+
/**
650+
* Commander.js tricks
651+
*/
649652
var app_conf = Config.transCMDToConf(opts);
650653
var appConf = {};
651654

652655
var ignoreFileArray = [];
653656

654-
if (!!opts.executeCommand)
655-
app_conf.exec_mode = 'fork';
656-
else if (opts.instances !== undefined)
657-
app_conf.exec_mode = 'cluster';
658-
else
659-
app_conf.exec_mode = 'fork';
660-
661657
if (typeof app_conf.name == 'function')
662658
delete app_conf.name;
663659

664660
delete app_conf.args;
665661

662+
// Retrieve arguments via -- <args>
666663
var argsIndex;
667664

668665
if (opts.rawArgs && (argsIndex = opts.rawArgs.indexOf('--')) >= 0)
@@ -677,7 +674,6 @@ class API {
677674

678675
app_conf = appConf[0];
679676

680-
681677
if (opts.ignoreWatch) {
682678
flagWatch.handleFolders(opts.ignoreWatch, ignoreFileArray);
683679
if (app_conf.ignore_watch) {
@@ -698,7 +694,6 @@ class API {
698694
hf.make_available_extension(opts, mas); // for -e flag
699695
mas.length > 0 ? app_conf.ignore_watch = mas : 0;
700696

701-
702697
/**
703698
* If -w option, write configuration to configuration.json file
704699
*/
@@ -713,6 +708,24 @@ class API {
713708
}
714709
}
715710

711+
series([
712+
restartExistingProcessName,
713+
restartExistingProcessId,
714+
restartExistingProcessPathOrStartNew
715+
], function(err, data) {
716+
if (err instanceof Error)
717+
return cb ? cb(err) : that.exitCli(conf.ERROR_EXIT);
718+
719+
var ret = {};
720+
721+
data.forEach(function(_dt) {
722+
if (_dt !== undefined)
723+
ret = _dt;
724+
});
725+
726+
return cb ? cb(null, ret) : that.speedList();
727+
});
728+
716729
/**
717730
* If start <app_name> start/restart application
718731
*/
@@ -758,7 +771,7 @@ class API {
758771
* Restart a process with the same full path
759772
* Or start it
760773
*/
761-
function restartExistingProcessPath(cb) {
774+
function restartExistingProcessPathOrStartNew(cb) {
762775
that.Client.executeRemote('getMonitorData', {}, function(err, procs) {
763776
if (err) return cb ? cb(new Error(err)) : that.exitCli(conf.ERROR_EXIT);
764777

@@ -828,24 +841,6 @@ class API {
828841
return false;
829842
});
830843
}
831-
832-
series([
833-
restartExistingProcessName,
834-
restartExistingProcessId,
835-
restartExistingProcessPath
836-
], function(err, data) {
837-
838-
if (err instanceof Error)
839-
return cb ? cb(err) : that.exitCli(conf.ERROR_EXIT);
840-
841-
var ret = {};
842-
data.forEach(function(_dt) {
843-
if (_dt !== undefined)
844-
ret = _dt;
845-
});
846-
847-
return cb ? cb(null, ret) : that.speedList();
848-
});
849844
}
850845

851846
/**

lib/Common.js

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,6 @@ Common.prepareAppConf = function(opts, app) {
124124
if ((ret = Common.sink.determineCron(app)) instanceof Error)
125125
return ret;
126126

127-
// Resolve paths
128-
// app.pm_exec_path = path.join(resolveCWD(app.cwd, opts.cwd), app.script);
129-
// app.pm_cwd = path.dirname(app.pm_exec_path);
130-
// console.log(' hads', app.pm_cwd);
131127
var cwd = null;
132128

133129
if (app.cwd) {
@@ -142,7 +138,6 @@ Common.prepareAppConf = function(opts, app) {
142138
// Full path script resolution
143139
app.pm_exec_path = path.resolve(cwd, app.script);
144140

145-
146141
// If script does not exist after resolution
147142
if (!fs.existsSync(app.pm_exec_path)) {
148143
var ckd;
@@ -267,20 +262,18 @@ Common.parseConfig = function(confObj, filename) {
267262
var yamljs = require('yamljs');
268263
var vm = require('vm');
269264

270-
if (!filename || filename == 'pipe' || filename == 'none' ||
265+
if (!filename ||
266+
filename == 'pipe' ||
267+
filename == 'none' ||
271268
filename.indexOf('.json') > -1) {
272269
var code = '(' + confObj + ')';
273270
var sandbox = {};
274-
if (semver.satisfies(process.version, '>= 0.12.0')) {
275-
return vm.runInThisContext(code, sandbox, {
276-
filename: path.resolve(filename),
277-
displayErrors: false,
278-
timeout: 1000
279-
});
280-
} else {
281-
// Use the Node 0.10 API
282-
return vm.runInNewContext(code, sandbox, filename);
283-
}
271+
272+
return vm.runInThisContext(code, sandbox, {
273+
filename: path.resolve(filename),
274+
displayErrors: false,
275+
timeout: 1000
276+
});
284277
}
285278
else if (filename.indexOf('.yml') > -1 ||
286279
filename.indexOf('.yaml') > -1) {
@@ -408,9 +401,8 @@ Common.sink.resolveInterpreter = function(app) {
408401
else if (app.exec_interpreter.indexOf('node@') > -1)
409402
resolveNodeInterpreter(app);
410403

411-
if (app.exec_interpreter.indexOf('python') > -1) {
404+
if (app.exec_interpreter.indexOf('python') > -1)
412405
app.env.PYTHONUNBUFFERED = '1'
413-
}
414406

415407
/**
416408
* Specific installed JS transpilers
@@ -652,13 +644,11 @@ Common.verifyConfs = function(appConfs){
652644

653645
if (app.instances == 'max')
654646
app.instances = 0;
647+
655648
// Sanity check, default to number of cores if value can't be parsed
656649
if (typeof(app.instances) === 'string')
657650
app.instances = parseInt(app.instances) || 0;
658651

659-
// Check Exec mode
660-
checkExecMode(app);
661-
662652
if (app.exec_mode != 'cluster_mode' &&
663653
!app.instances && typeof(app.merge_logs) == 'undefined')
664654
app.merge_logs = true;
@@ -707,22 +697,6 @@ Common.getCurrentUsername = function(){
707697
return current_user;
708698
}
709699

710-
/**
711-
* Check if right Node.js version for cluster mode
712-
* @param {Object} conf
713-
*/
714-
function checkExecMode(app) {
715-
if (app.exec_mode === 'cluster' ||
716-
app.exec_mode === 'cluster_mode' ||
717-
app.instances && app.exec_mode === undefined)
718-
app.exec_mode = 'cluster_mode';
719-
else
720-
app.exec_mode = 'fork_mode';
721-
722-
if (app.instances && app.exec_mode === undefined)
723-
app.exec_mode = 'cluster_mode';
724-
}
725-
726700
/**
727701
* Render an app name if not existing.
728702
* @param {Object} conf
@@ -737,7 +711,6 @@ function prepareAppName(conf){
737711
}
738712
}
739713

740-
741714
/**
742715
* Show warnings
743716
* @param {String} warning

test/e2e.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ bash ./test/e2e/cli/env-refresh.sh
3636
spec "Environment refresh on restart"
3737
bash ./test/e2e/cli/extra-lang.sh
3838
spec "Various programming languages checks (Python, PHP)"
39+
bash ./test/e2e/cli/python-support.sh
40+
spec "Python support checks"
3941
bash ./test/e2e/cli/multiparam.sh
4042
spec "Multiparam process management"
4143
bash ./test/e2e/cli/smart-start.sh
@@ -62,8 +64,6 @@ bash ./test/e2e/cli/watch.sh
6264
spec "watch system tests"
6365
bash ./test/e2e/cli/right-exit-code.sh
6466
spec "Verification exit code"
65-
bash ./test/e2e/cli/harmony.sh
66-
spec "Harmony test"
6767
bash ./test/e2e/cli/fork.sh
6868
spec "Fork system working"
6969
bash ./test/e2e/cli/piped-config.sh

test/e2e/cli/harmony.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

test/e2e/cli/python-support.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
3+
SRC=$(cd $(dirname "$0"); pwd)
4+
source "${SRC}/../include.sh"
5+
6+
cd $file_path/extra-lang
7+
8+
which python
9+
spec "should have python installed"
10+
11+
#
12+
# Config file
13+
#
14+
15+
$pm2 start app-python.config.js --only 'echo-python-1'
16+
should 'should mode be fork' 'fork_mode' 1
17+
should 'should have started 1 apps' 'online' 1
18+
19+
$pm2 delete all
20+
21+
# Check with multi instances
22+
$pm2 start app-python.config.js --only 'echo-python-max'
23+
should 'should mode be fork' 'fork_mode' 4
24+
should 'should have started 4 apps' 'online' 4
25+
26+
# Should keep same params on restart
27+
$pm2 restart all
28+
should 'should have restarted processes' 'restart_time: 1' 4
29+
should 'should mode be fork' 'fork_mode' 4
30+
31+
$pm2 delete all
32+
33+
#
34+
# CLI
35+
#
36+
37+
$pm2 start echo.py
38+
should 'should mode be fork' 'fork_mode' 1
39+
should 'should have started 1 apps' 'online' 1
40+
41+
$pm2 delete all
42+
43+
$pm2 start echo.py -i 4
44+
should 'should mode be fork' 'fork_mode' 4
45+
should 'should have started 4 apps' 'online' 4
46+
47+
$pm2 restart all
48+
should 'should have restarted processes' 'restart_time: 1' 4
49+
should 'should mode be fork' 'fork_mode' 4
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = {
2+
apps : [{
3+
name: 'echo-python-1',
4+
cmd: 'echo.py',
5+
max_memory_restart: '1G',
6+
env: {
7+
NODE_ENV: 'development'
8+
},
9+
env_production : {
10+
NODE_ENV: 'production'
11+
}
12+
},{
13+
name: 'echo-python-max',
14+
cmd: 'echo.py',
15+
instances: 4,
16+
env: {
17+
NODE_ENV: 'development'
18+
},
19+
env_production : {
20+
NODE_ENV: 'production'
21+
}
22+
}]
23+
};

test/fixtures/extra-lang/apps.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"interpreter" : "/usr/bin/python3",
44
"name" : "echo-python",
55
"script" : "echo.py",
6-
"interpreter_args" : "-u",
76
"log" : "python-app.log",
87
"combine_logs" : true,
98
"env" : {

test/fixtures/harmony.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

test/fixtures/harmony.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)