Skip to content

Commit

Permalink
fix: Unitech#4442 allow to pass path in direct pm2 execution
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Oct 14, 2019
1 parent cc48bd4 commit b063733
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -22,3 +22,4 @@ yarn.lock
e2e_time
unit_time
*.heapprofile
a.out
2 changes: 1 addition & 1 deletion constants.js
Expand Up @@ -44,7 +44,7 @@ var csts = {
ERROR_EXIT : 1,
CODE_UNCAUGHTEXCEPTION : 1,

IS_WINDOWS : (process.platform === 'win32' || process.platform === 'win64'),
IS_WINDOWS : (process.platform === 'win32' || process.platform === 'win64' || /^(msys|cygwin)$/.test(process.env.OSTYPE)),
ONLINE_STATUS : 'online',
STOPPED_STATUS : 'stopped',
STOPPING_STATUS : 'stopping',
Expand Down
7 changes: 7 additions & 0 deletions examples/c-compile/hello.c
@@ -0,0 +1,7 @@
#include <stdio.h>
int main()
{
// printf() displays the string inside quotation
printf("Hello, Wss asdsad!\n");
return 0;
}
9 changes: 9 additions & 0 deletions examples/npm-start/http.js
@@ -0,0 +1,9 @@

var http = require('http');

var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('hey');
}).listen(process.env.PORT || 8000, function() {
console.log('App listening on port %d', server.address().port);
});
12 changes: 12 additions & 0 deletions examples/npm-start/package.json
@@ -0,0 +1,12 @@
{
"name": "npm-start",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node http.js"
},
"author": "",
"license": "ISC"
}
25 changes: 16 additions & 9 deletions lib/Common.js
Expand Up @@ -660,18 +660,25 @@ Common.verifyConfs = function(appConfs) {
* If command is like pm2 start "python xx.py --ok"
* Then automatically start the script with bash -c and set a name eq to command
*/
if (app.script && app.script.indexOf(' ') > -1 && app.script === path.basename(app.script)) {
if (app.script && app.script.indexOf(' ') > -1 && cst.IS_WINDOWS === false) {
var _script = app.script;
if (require('shelljs').which('bash'))

if (require('shelljs').which('bash')) {
app.script = 'bash';
else if (require('shelljs').which('sh'))
app.args = ['-c', _script];
if (!app.name) {
app.name = _script
}
}
else if (require('shelljs').which('sh')) {
app.script = 'sh';
else
throw new Error('bash and sh not available in $PATH')

app.args = ['-c', _script];
if (!app.name) {
app.name = _script
app.args = ['-c', _script];
if (!app.name) {
app.name = _script
}
}
else {
warn('bash or sh not available in $PATH, keeping script as is')
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/e2e/cli/start-app.sh
Expand Up @@ -34,3 +34,12 @@ should 'should have started command' 'online' 1
should 'should have not been restarted' 'restart_time: 0' 1
cat test-conf.log | grep "test_val" 2> /dev/null
spec "should have printed the test_val"

#
# Compile C Program
#
cd $file_path/c-compile
$pm2 start "cc hello.c; ./a.out" -l c-log.log --merge-logs
sleep 1
cat c-log.log | grep "Hello World" &> /dev/null
spec "should have printed undefined env var"
7 changes: 7 additions & 0 deletions test/fixtures/c-compile/hello.c
@@ -0,0 +1,7 @@
#include <stdio.h>
int main()
{
// printf() displays the string inside quotation
printf("Hello World\n");
return 0;
}

0 comments on commit b063733

Please sign in to comment.