Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: bash and sh not available in $PATH #3767

Closed
newlukai opened this issue Jul 5, 2018 · 9 comments
Closed

Error: bash and sh not available in $PATH #3767

newlukai opened this issue Jul 5, 2018 · 9 comments

Comments

@newlukai
Copy link

newlukai commented Jul 5, 2018

What's going wrong?

When I try to start my development environment using pm2 start <configfile>, pm2 exits with an error "bash and sh not available in $PATH". It's not really surprising to me since I'm working on Windows.

How could we reproduce this issue?

Create a config file as follows:
{ apps: [{ "name": "mongo", "script": "C:\\Program Files\MongoDB\Server\3.6\\bin\\mongod.exe", "args": "--dbpath C:\\some\\db\\path" }] }

and start pm2 using pm2 start <pathToThatConfigFile>.

Supporting information

pm2\lib\Common.js.verifyConf looks for a space in the script property. If a space is found, it assumes that this script should be run in bash/sh.
But a space could also appear in a binary/command path, on Windows, Mac OS and Linux. Either I don't know how to properly configure pm2 to run MongoDB (or any other non-node program) or it's a bug, I guess.

===============================================================================
--- PM2 REPORT (Thu Jul 05 2018 09:43:37 GMT+0200 (Mitteleuropäische Sommerzeit))
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 3.0.0
node version         : 6.10.3
node path            : undefined
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\someUserName\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 79min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 3.0.0
node version         : 6.10.3
node path            : undefined
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\someUserName\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0                : node
user                 : someUserName
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
cpus nb              : 8
freemem              : 8209297408
totalmem             : 17054912512
home                 : C:\Users\someUserName
===============================================================================
@Unitech Unitech added the T: Bug label Jul 5, 2018
@Unitech
Copy link
Owner

Unitech commented Jul 5, 2018

af60e99

wallet77 added a commit that referenced this issue Jul 10, 2018
hotfix: fix #3767, do not consider as a command if space and slash ar…
@newlukai
Copy link
Author

newlukai commented Aug 6, 2018

Thanks. Is working again. 👍

@KnightCoder
Copy link

I'm getting this same error when I tried to run nginx as a pm2 service.
pm2 version: 3.0.3

This is my config file for nginx.

module.exports = {
  apps : [{
    name      : 'nginx',
    script    : 'start nginx.exe',
    env: {
      NODE_ENV: 'development'
    },
    env_production : {
      NODE_ENV: 'production'
    }
  }]
};

This is the error output:

pm2 start ecosystem.config.js

C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\Common.js:623
        throw new Error('bash and sh not available in $PATH')
        ^

Error: bash and sh not available in $PATH
    at Object.Common.verifyConfs (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\Common.js:623:15)
    at API._startJson (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\API.js:882:27)
    at API.start (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\lib\API.js:324:12)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\bin\pm2:299:13
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\async\dist\async.js:3110:16
    at replenish (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\async\dist\async.js:1011:17)
    at C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\async\dist\async.js:1016:9
    at Object.eachLimit$1 (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\async\dist\async.js:3196:24)
    at Command.<anonymous> (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\bin\pm2:298:13)
    at Command.listener (C:\Users\Administrator\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:315:8)

@Sodj
Copy link

Sodj commented Sep 14, 2018

I still have this error when running pm2 start "npm start" in my react project
I have pm2 v3.1.2

@snsarma
Copy link

snsarma commented May 10, 2019

Hi IS there a fix for this , I have been encountering the same error for the past couple of days when I do a pm2 start ecosystem.config.js

pm2 start ecosystem.config.js
C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\lib\Common.js:669
throw new Error('bash and sh not available in $PATH')
^

Error: bash and sh not available in $PATH
at Object.Common.verifyConfs (C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\lib\Common.js:669:15)
at API._startJson (C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\lib\API.js:926:27)
at API.start (C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\lib\API.js:334:12)
at C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\bin\pm2:291:13
at C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\withoutIndex.js:9:16
at replenish (C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\eachOfLimit.js:66:17) at C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\eachOfLimit.js:71:9
at eachLimit (C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\node_modules\async\forEachLimit.js:43:36)
at Command. (C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\bin\pm2:290:7)
at Command.listener (C:\Users\SSarma\AppData\Roaming\npm\node_modules\pm2\node_modules\commander\index.js:315:8)

@fmalk
Copy link

fmalk commented May 15, 2019

This error appeared to me as well.
As indicated by @newlukai :

pm2\lib\Common.js.verifyConf looks for a space in the script property. If a space is found, it assumes that this script should be run in bash/sh.

In Windows, avoid using spaces in the script parameter of pm2.config.js. If you have and index.js as starting point, you can just use "script": "./folder" and pm2 will run it.

@snsarma
Copy link

snsarma commented May 15, 2019

@fmalk Thanks for the inputs , I am able to start pm2 via ecosystem.config.js , I had one more question , Following is the content of my ecosystem.config.js file, I need to get the values stored in env and env_production in a variable in my component so that based on that I can hit the appropriate API.
Could you please suggest how I can retrieve the values stored in NODE_ENV of env and env_production.
This is the final blocker in our deployment as we have had to manually change them during the deployment.

module.exports = {
apps : [{
name: 'API',
script: './build/server.js',
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
args: 'one two',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
}
}],
deploy : {
production : {
user : 'node',
host : '212.83.163.1',
ref : 'origin/master',
repo : 'git@github.com:repo.git',
path : '/var/www/production',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
}
}
};

@fmalk
Copy link

fmalk commented May 16, 2019

@snsarma not really an expert but isn't what you're trying to do achieavable by running

pm2 start <config> --env production

@snsarma
Copy link

snsarma commented May 16, 2019

@fmalk Thanks for the response , when I run the above , I am not able to view my app in the browser and the environment variable isn't retrieved either.The pm2 gets started but the app is not up in my browser , I just need to figure a way to differentiate between development and production environment. Based on that the appropriate API is hit. Any inputs are welcome.

inerc pushed a commit to inerc/pm2 that referenced this issue Feb 11, 2020
inerc pushed a commit to inerc/pm2 that referenced this issue Feb 11, 2020
inerc pushed a commit to inerc/pm2 that referenced this issue Feb 11, 2020
hotfix: fix Unitech#3767, do not consider as a command if space and slash ar…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants