bash: pm2: command not found
Asked Answered
F

4

7

I can't run pm2 on ubuntu box. I'm not sure what's the problem. The pm2 is installed globally.

npm list -g --depth=0
/opt/nodejs/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

But I still get

pm2
-bash: pm2: command not found

if I run other app

userdown
Starting Script is not provided

versions

node v4.5.0
npm  v2.15.9

log from installation:

sudo npm install pm2 -g
npm WARN optional dep failed, continuing [email protected]
/opt/nodejs/bin/pm2 -> /opt/nodejs/lib/node_modules/pm2/bin/pm2
/opt/nodejs/bin/rundev -> /opt/nodejs/lib/node_modules/pm2/bin/rundev
/opt/nodejs/bin/pm2-dev -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-dev
/opt/nodejs/bin/pm2-docker -> /opt/nodejs/lib/node_modules/pm2/bin/pm2-docker
[email protected] /opt/nodejs/lib/node_modules/pm2
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected]
kamil@vps2:~$ pm2
-bash: pm2: command not found

ubuntu version:

uname -a
Linux vps2 2.6.32-042stab111.11 #1 SMP Tue Sep 1 18:19:12 MSK 2015 x86_64 x86_64 x86_64 GNU/Linux
Fuscous answered 25/11, 2016 at 7:12 Comment(1)
What does this question have to do with bash?Tussock
F
15

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 :)

Fuscous answered 25/11, 2016 at 11:22 Comment(1)
although i did not found userdown but still sudo ln -s /opt/nodejs/bin/pm2 /usr/bin/pm2 worked Thanks :)Burck
A
4

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
Acey answered 25/11, 2016 at 21:12 Comment(1)
doing like so status always stop even if you run start command.Sesquialtera
C
1

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);

Contretemps answered 8/3, 2017 at 19:43 Comment(0)
L
1

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

Lorenelorens answered 27/1, 2019 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.