diff --git a/lib/Common.js b/lib/Common.js index fb1b1e47..757def0b 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -6,6 +6,7 @@ var fs = require('fs'); var path = require('path'); var util = require('util'); var cronJob = require('cron').CronJob; +var isBinary = require("isbinaryfile"); var UX = require('./CliUx.js'); var cst = require('../constants.js'); @@ -61,7 +62,11 @@ Common.resolveAppPaths = function(app, cwd, outputter) { if (extItps[path.extname(app.script)] != 'node' && path.extname(app.script) != '.coffee') app.exec_mode = 'fork_mode'; } else { - app.exec_interpreter = 'node'; + if (isBinary(app.script)) { + app.exec_interpreter = 'none'; + app.exec_mode = 'fork_mode'; + } else + app.exec_interpreter = 'node'; } } diff --git a/package.json b/package.json index 8b7c3f71..9191c5d8 100644 --- a/package.json +++ b/package.json @@ -118,39 +118,37 @@ "pm2": "./bin/pm2" }, "dependencies": { - "async" : "~0.9.0", - "chalk" : "~0.5.1", - "chokidar" : "~0.10.1", - "cli-table" : "0.3.0", - "coffee-script" : "1.8.0", - "colors" : "0.6.2", - "commander" : "2.4.0", - "cron" : "1.0.5", - "debug" : "2.1.0", - "eventemitter2" : "0.4.14", - "json-stringify-safe" : "5.0.0", - "moment" : "~2.8.3", - "nssocket" : "0.5.1", - "pidusage" : "0.1.0", - - "axm" : "latest", - "vizion" : "latest", - - "pm2-axon" : "2.0.7", - "pm2-axon-rpc" : "0.3.6", - "pm2-deploy" : "latest", - "pm2-multimeter" : "0.1.2", - "pm2-rpc-fallback" : "3.0.9", - - "punt" : "2.2.0", - "shelljs" : "0.3.0" + "async": "~0.9.0", + "axm": "latest", + "chalk": "~0.5.1", + "chokidar": "~0.10.1", + "cli-table": "0.3.0", + "coffee-script": "1.8.0", + "colors": "0.6.2", + "commander": "2.4.0", + "cron": "1.0.5", + "debug": "2.1.0", + "eventemitter2": "0.4.14", + "isbinaryfile": "^2.0.2", + "json-stringify-safe": "5.0.0", + "moment": "~2.8.3", + "nssocket": "0.5.1", + "pidusage": "0.1.0", + "pm2-axon": "2.0.7", + "pm2-axon-rpc": "0.3.6", + "pm2-deploy": "latest", + "pm2-multimeter": "0.1.2", + "pm2-rpc-fallback": "3.0.9", + "punt": "2.2.0", + "shelljs": "0.3.0", + "vizion": "latest" }, "devDependencies": { "mocha": "^1.20.1", "should": "^4.0.0", "better-assert": "^1.0.0", "promise-spawner": "^0.0.3", - "punt" : "*" + "punt": "*" }, "optionalDependencies": { "pm2-logs": "~0.1.1", diff --git a/test/bash/binary.sh b/test/bash/binary.sh new file mode 100644 index 00000000..da4efdc9 --- /dev/null +++ b/test/bash/binary.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +SRC=$(cd $(dirname "$0"); pwd) +source "${SRC}/include.sh" + +echo -e "\033[1mRunning tests:\033[0m" + +cd $file_path + +# +# Testing pm2 execution of binary files +# +$pm2 start `which watch` -- ls + +OUT=`$pm2 prettylist | grep exec_interpreter | sed "s/[\'|,|:]//g" | awk -F' ' '{print $2}'` +[ $OUT = "none" ] || fail "$1" +success "$1" + +$pm2 kill +$pm2 start binary-js-file + +OUT=`$pm2 prettylist | grep exec_interpreter | sed "s/[\'|,|:]//g" | awk -F' ' '{print $2}'` +[ $OUT = "node" ] || fail "$1" +success "$1" + +$pm2 kill +$pm2 start binary-js-file.js + +OUT=`$pm2 prettylist | grep exec_interpreter | sed "s/[\'|,|:]//g" | awk -F' ' '{print $2}'` +[ $OUT = "node" ] || fail "$1" +success "$1" + +$pm2 kill +$pm2 start binary-py-file.py + +OUT=`$pm2 prettylist | grep exec_interpreter | sed "s/[\'|,|:]//g" | awk -F' ' '{print $2}'` +[ $OUT = "python" ] || fail "$1" +success "$1" + +$pm2 kill diff --git a/test/fixtures/binary-js-file b/test/fixtures/binary-js-file new file mode 100644 index 00000000..fb17b2f3 --- /dev/null +++ b/test/fixtures/binary-js-file @@ -0,0 +1 @@ +setInterval(function () {console.log("test")}, 5000) \ No newline at end of file diff --git a/test/fixtures/binary-js-file.js b/test/fixtures/binary-js-file.js new file mode 100644 index 00000000..fb17b2f3 --- /dev/null +++ b/test/fixtures/binary-js-file.js @@ -0,0 +1 @@ +setInterval(function () {console.log("test")}, 5000) \ No newline at end of file diff --git a/test/fixtures/binary-py-file.py b/test/fixtures/binary-py-file.py new file mode 100644 index 00000000..1d8a5ad0 --- /dev/null +++ b/test/fixtures/binary-py-file.py @@ -0,0 +1,2 @@ +while True: + print 'hello' diff --git a/test/main.sh b/test/main.sh index df1ce4fd..b90c479e 100644 --- a/test/main.sh +++ b/test/main.sh @@ -55,6 +55,8 @@ bash ./test/bash/reset.sh spec "Reset meta" bash ./test/bash/startOrX.sh spec "startOrX commands" +bash ./test/bash/binary.sh +spec "binary test" bash ./test/bash/inside-pm2.sh spec "Starting a process inside a PM2 process"