diff --git a/bin/pm2 b/bin/pm2 index 62dcbf8a..002657e7 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -929,9 +929,10 @@ commander.command('deepUpdate') // commander.command('serve [path] [port]') .alias('expose') + .option('--port [port]', 'specify port to listen to') .description('serve a directory over http via port') - .action(function (path, port) { - pm2.serve(path, port, commander); + .action(function (path, port, cmd) { + pm2.serve(path, port || cmd.port, commander); }); commander.command('examples') diff --git a/lib/Common.js b/lib/Common.js index 4981afd9..35b13389 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -639,7 +639,8 @@ Common.verifyConfs = function(appConfs){ // Check Exec mode checkExecMode(app); - if (app.exec_mode != 'cluster_mode' && !app.instances) + if (app.exec_mode != 'cluster_mode' && + !app.instances && typeof(app.merge_logs) == 'undefined') app.merge_logs = true; // Render an app name if not existing. diff --git a/test/e2e/cli/serve.sh b/test/e2e/cli/serve.sh index 48289bbe..e4179af0 100644 --- a/test/e2e/cli/serve.sh +++ b/test/e2e/cli/serve.sh @@ -4,18 +4,19 @@ SRC=$(cd $(dirname "$0"); pwd) source "${SRC}/../include.sh" cd $file_path/serve - +PORT=8081 +PORT_2=8082 echo "################## PM2 SERVE ###################" -$pm2 serve +$pm2 serve --port $PORT should 'should have started serving dir' 'online' 1 -curl http://localhost:8080/ > /tmp/tmp_out.txt +curl http://localhost:$PORT/ > /tmp/tmp_out.txt OUT=`cat /tmp/tmp_out.txt | grep -o "good shit" | wc -l` [ $OUT -eq 1 ] || fail "should have served index file under /" success "should have served index file under /" -curl http://localhost:8080/index.html > /tmp/tmp_out.txt +curl http://localhost:$PORT/index.html > /tmp/tmp_out.txt OUT=`cat /tmp/tmp_out.txt | grep -o "good shit" | wc -l` [ $OUT -eq 1 ] || fail "should have served index file under /index.html" success "should have served index file under /index.html" @@ -23,31 +24,31 @@ success "should have served index file under /index.html" echo "Shutting down the server" $pm2 delete all -curl http://localhost:8080/index.html > /tmp/tmp_out.txt +curl http://localhost:$PORT/index.html > /tmp/tmp_out.txt OUT=`cat /tmp/tmp_out.txt | grep -o "good shit" | wc -l` [ $OUT -eq 0 ] || fail "should be offline" success "should be offline" -$pm2 serve . 8000 +$pm2 serve . $PORT_2 should 'should have started serving dir' 'online' 1 -curl http://localhost:8000/index.html > /tmp/tmp_out.txt +curl http://localhost:$PORT_2/index.html > /tmp/tmp_out.txt OUT=`cat /tmp/tmp_out.txt | grep -o "good shit" | wc -l` -[ $OUT -eq 1 ] || fail "should be listening on port 8000" -success "should be listening on port 8000" +[ $OUT -eq 1 ] || fail "should be listening on port $PORT_2" +success "should be listening on port $PORT_2" $pm2 delete all -$pm2 serve . 8000 --name frontend +$pm2 serve . $PORT_2 --name frontend should 'should have started serving dir' 'online' 1 should 'should have custom name' 'frontend' 7 -curl http://localhost:8000/index.html > /tmp/tmp_out.txt +curl http://localhost:$PORT_2/index.html > /tmp/tmp_out.txt OUT=`cat /tmp/tmp_out.txt | grep -o "good shit" | wc -l` -[ $OUT -eq 1 ] || fail "should be listening on port 8000" -success "should be listening on port 8000" +[ $OUT -eq 1 ] || fail "should be listening on port $PORT_2" +success "should be listening on port $PORT_2" -curl http://localhost:8000/yolo.html > /tmp/tmp_out.txt +curl http://localhost:$PORT_2/yolo.html > /tmp/tmp_out.txt OUT=`cat /tmp/tmp_out.txt | grep -o "your file doesnt exist" | wc -l` [ $OUT -eq 1 ] || fail "should have served custom 404 file" success "should have served custom 404 file" diff --git a/test/e2e/misc/cron-system.sh b/test/e2e/misc/cron-system.sh index f97376c1..d9dbbe0e 100644 --- a/test/e2e/misc/cron-system.sh +++ b/test/e2e/misc/cron-system.sh @@ -16,12 +16,12 @@ spec "Should cron restart echo.js" $pm2 delete all -> mock-0.log +> mock.log $pm2 start cron/mock-cron.js -o mock.log sleep 3 should 'should app been restarted when cron in fork mode' 'restart_time: 0' 0 -cat mock-0.log | grep "SIGINT" +cat mock.log | grep "SIGINT" spec "1# Should cron exit call SIGINT handler" $pm2 delete all @@ -29,7 +29,7 @@ $pm2 delete all $pm2 start cron/mock-cron.js -o mock.log -i 1 sleep 3 should 'should app been restarted when cron in cluster mode' 'restart_time: 0' 0 -cat mock-0.log | grep "SIGINT" +cat mock.log | grep "SIGINT" spec "2# Should cron exit call SIGINT handler" $pm2 delete all @@ -38,7 +38,7 @@ $pm2 delete all $pm2 start cron/mock-cron-no-exit.js -o mock.log sleep 3 should 'should app been restarted' 'restart_time: 0' 0 -cat mock-0.log | grep "SIGINT" +cat mock.log | grep "SIGINT" spec "3# Should cron exit call SIGINT handler" @@ -52,7 +52,7 @@ spec "Should cron restart delayed sigint" sleep 100 -cat cron-0.log | grep "SIGINT cb called" +cat cron.log | grep "SIGINT cb called" spec "Should cron exit call SIGINT handler" should 'should app been restarted' 'restart_time: 1' 1 diff --git a/test/e2e/misc/inside-pm2.sh b/test/e2e/misc/inside-pm2.sh index 377241d6..6646e8fb 100644 --- a/test/e2e/misc/inside-pm2.sh +++ b/test/e2e/misc/inside-pm2.sh @@ -12,7 +12,7 @@ echo -e "\033[1mRunning tests:\033[0m" #################################################################### TEST_VARIABLE='hello1' $pm2 start startProcessInsidePm2.json ->inside-out-1.log +>inside-out.log sleep 1 @@ -25,12 +25,12 @@ $pm2 list should 'child process should be started' 'pm_id: 1' 2 should 'restarted status should be zero' "restart_time: 0" 2 -grep "hello1" inside-out-1.log &> /dev/null +grep "hello1" inside-out.log &> /dev/null spec "Child should have hello1 variable" TEST_VARIABLE='hello2' $pm2 restart "insideProcess" --update-env sleep 1 -grep "hello2" inside-out-1.log &> /dev/null +grep "hello2" inside-out.log &> /dev/null spec "Child should have hello2 variable after restart" # Call bash script that restarts app diff --git a/test/fixtures/path-resolution/ecosystem3.config.js b/test/fixtures/path-resolution/ecosystem3.config.js new file mode 100644 index 00000000..d201bfdd --- /dev/null +++ b/test/fixtures/path-resolution/ecosystem3.config.js @@ -0,0 +1,15 @@ +module.exports = { + /** + * Application configuration section + * http://pm2.keymetrics.io/docs/usage/application-declaration/ + */ + apps : [ + { + name : "test-cluster", + script : "./echo.js", + out_file : 'echo-out.log', + error_file : 'echo-err.log', + instances: 4 + } + ] +} diff --git a/test/programmatic/logs.js b/test/programmatic/logs.js index 6cf72e6b..8f73f908 100644 --- a/test/programmatic/logs.js +++ b/test/programmatic/logs.js @@ -33,7 +33,8 @@ describe('Programmatic log feature test', function() { pm2.start({ script: './echo.js', error_file : 'error-echo.log', - out_file : 'out-echo.log' + out_file : 'out-echo.log', + merge_logs: false }, function(err, procs) { should(err).be.null(); diff --git a/test/programmatic/path_resolution.mocha.js b/test/programmatic/path_resolution.mocha.js index 2c6f40b1..a29ed0d1 100644 --- a/test/programmatic/path_resolution.mocha.js +++ b/test/programmatic/path_resolution.mocha.js @@ -6,6 +6,7 @@ var PM2 = require('../..'); var should = require('should'); describe('Path resolution in configuration file', function() { + this.timeout(4000) before(function(done) { PM2.delete('all', function() { done() } ); }); @@ -16,8 +17,8 @@ describe('Path resolution in configuration file', function() { it('should resolve paths (home)', function(done) { PM2.start('./path-resolution/ecosystem.config.js', function(err, proc) { - should(proc[0].pm2_env.pm_err_log_path).eql(path.join(process.env.HOME, 'echo-err-0.log')); - should(proc[0].pm2_env.pm_out_log_path).eql(path.join(process.env.HOME, 'echo-out-0.log')); + should(proc[0].pm2_env.pm_err_log_path).eql(path.join(process.env.HOME, 'echo-err.log')); + should(proc[0].pm2_env.pm_out_log_path).eql(path.join(process.env.HOME, 'echo-out.log')); should(proc[0].pm2_env.pm_pid_path).eql(path.join(process.env.HOME, 'echo-pid.log')); done(); }); @@ -25,10 +26,22 @@ describe('Path resolution in configuration file', function() { it('should resolve paths (local)', function(done) { PM2.start('./path-resolution/ecosystem2.config.js', function(err, proc) { - should(proc[0].pm2_env.pm_err_log_path).eql(path.join(process.cwd(), 'echo-err-0.log')); - should(proc[0].pm2_env.pm_out_log_path).eql(path.join(process.cwd(), 'echo-out-0.log')); + should(proc[0].pm2_env.pm_err_log_path).eql(path.join(process.cwd(), 'echo-err.log')); + should(proc[0].pm2_env.pm_out_log_path).eql(path.join(process.cwd(), 'echo-out.log')); should(proc[0].pm2_env.pm_pid_path).eql(path.join(process.cwd(), 'echo-pid.log')); done(); }); }); + + it('should auto prefix log path on cluster mode', function(done) { + PM2.start('./path-resolution/ecosystem3.config.js', function(err, proc) { + should(proc[0].pm2_env.pm_err_log_path).eql(path.join(process.cwd(), 'echo-err-0.log')); + should(proc[0].pm2_env.pm_out_log_path).eql(path.join(process.cwd(), 'echo-out-0.log')); + + should(proc[1].pm2_env.pm_err_log_path).eql(path.join(process.cwd(), 'echo-err-1.log')); + should(proc[1].pm2_env.pm_out_log_path).eql(path.join(process.cwd(), 'echo-out-1.log')); + done(); + }); + }); + });