bash: pm2: command not found

你离开我真会死。 提交于 2019-12-06 14:22:04

Ok got answer myself. I check what happens for

whereis pm2
pm2: /opt/nodejs/bin/pm2

then I checked

whereis userdown
userdown: /usr/bin/userdown /usr/bin/X11/userdown /opt/nodejs/bin/userdown

hmm in /usr/bin.... So I did

sudo ln -s /opt/nodejs/bin/pm2 /usr/bin/pm2 

and it works :)

The problem is that you are running NPM as sudo, so you will only be able to access it using:

sudo pm2 start server.js

Install without sudo, you may even install without the -gflag and call it directly from node_modules directory. This may be useful if you do not have root (admin) privileges in the machine you're working on.

npm install pm2
./node_modules/.bin/pm2 start server.js

Follow the proper nodejs isntallation, npm permission fixes and npm global packages tweaks:

@ https://gist.github.com/servercharlie/9a7e0d0e1645b4c6fbfe5de566fcf1ca

Your script needs to do some thing that requires root privilege? (ie: you're getting an error on using port 80)

[wrong] - trying to run w/ sudo

[correct] - login as root "sudo su" then do pm2 start app.js --name "whatever" --watch

that does it, no need to configure any bashrc or profile files.

extra: worried about your app doing crazy shit? (ie, since it's executed as root, the script can use nodejs's exec and do some crazy stuff.)

hence. do this: do the root-stuff first with your script, then lower your privilege after some timeout:

// i use port 80 first.. at this point the script's uid is ROOT.

app.listen(80);

// after 2 seconds we switch to uid AZUREUSER, which obviously isn't root anymore.

setTimeout(function(){

process.setuid("azureuser");

}, 2000);

In my scenario I wrote a shell script that was triggered by jenkins build and

I fixed using following link

https://github.com/Unitech/pm2-deploy/issues/41

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!