Pm2: Apps not showing on list

Created on 3 Feb 2015  ยท  19Comments  ยท  Source: Unitech/pm2

Hi
I've started two apps with pm2. Both apps are working (I get a response from the API) but they don't show when I execute pm2 list. Any ideas on what can be causing this? I'm running a ec2 ubuntu instance.

deploy@ip-172-31-25-115:~$ ps aux | grep node
deploy    1515  0.2  6.5 789492 66724 ?        Ssl  15:25   0:00 node /srv/node/pse/source/app.js
deploy    1518  0.3  7.3 992580 74780 ?        Ssl  15:25   0:01 node /srv/node/pse/source/bj.js
deploy    1833  0.0  0.0  10440   932 pts/0    S+   15:30   0:00 grep --color=auto node
deploy@ip-172-31-25-115:~$ pm2 list
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name โ”‚ id โ”‚ mode โ”‚ PID โ”‚ status โ”‚ restarted โ”‚ uptime โ”‚ memory โ”‚ watching โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
 Use `pm2 info <id|name>` to get more details about an app

Thanks!

Most helpful comment

You likely launched your apps with a different PM2_HOME location.

Check to see where you have pm2 daemons running:

$ sudo ps aux | grep pm2

Chances are you have more than one, e.g.:

PM2 v2.0.18: God Daemon (/etc/.pm2)
PM2 v2.0.18: God Daemon (/home/root/.pm2)

The daemon that is running your applications will have .pid files in PM2_HOME/pids. Find out which one that is (probably /etc/.pm2/pids).

Then set the PM2_HOME variable and try again:

$ sudo PM2_HOME=/etc/.pm2 pm2 list

You'll probably want to relocate your apps to run from a PM2_HOME other than /etc/.pm2

All 19 comments

+1, been getting this too recently.

How did you start your apps? Different users?

I used this to start pm2

sudo npm install pm2 -g
pm2 ls
sudo env PATH=$PATH:`dirname $(which pm2)` pm2 startup ubuntu -u www-data

And my post-deploy hook ends with:

pm2 startOrRestart ecosystem.staging.json5 --env staging

which is executed with the deploy user. I tried executing the startup script with ubuntu user and deploy user, but neither work.

So there is a user conflict here.

You need to install the package globally for your deploy user - using nvm it's easy as npm i pm2 -g without sudo.
Then:

sudo env PATH=$PATH:`dirname $(which pm2)` pm2 startup ubuntu -u deploy 
#notice the -u user must be the same as the one which installed pm2

And everything should work just fine!

Explanation:
The issue here is that every user is using a different pm2 socket to communicate with it's processes. So, when you start your processes as www-data, when the user deploy launches pm2 list there will be no processes. If www-data launched pm2 list he would see it's processes.

Hope that's clear enough ;).

@soyuka everything works fine for me for a while, and then it disappears after using the API in node.

Let me see if I can get something together to consistently reproduce. Its intermittent at the min.

The API in node is being used inside a PM2 launched process if that makes any difference?

@soyuka thanks for the explanation.
What I don't get is how do I tell pm2 to use www-data to start a process. Do I need to run pm2 start with such user?

Yes.

Same virtual machine, 2 different users, 2 different node versions, 2 different pm2.

You'll notice that when I call pm2 list on the user I'm only retrieving it's own processes.

@soyuka I couldn't replicate the issue when upgrading node versions.
Must have been something in there.

sudo env PATH=$PATH:dirname $(which pm2) pm2 startup ubuntu -u deploy

@soyuka, what does the -u deploy option do? It's not documented in pm2 startup --help. Running pm2 alone shoes the option, so perhaps it should be documented in pm2 startup --help as well?

I seem to get the same error, but I can't even see the processes started by the same user. After a while, they just dissapear from the list, only that latest started apps appear. (There pid is saved in the same folder as the more recent ones, so I really don't get why this is happening).

i'm seeing this - same user, but not showing in the list:

root@therms-app-sandbox:~# lsof -i :1338
COMMAND   PID USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
node    10305 root   36u  IPv6 4381592      0t0  TCP 159.203.240.135:1338->12.183.186.157:61005 (ESTABLISHED)
node    10305 root   37u  IPv6 4381593      0t0  TCP 159.203.240.135:1338->12.183.186.157:61006 (ESTABLISHED)
node    10305 root   38u  IPv6 4381651      0t0  TCP 159.203.240.135:1338->12.183.186.157:61008 (ESTABLISHED)
PM2     23518 root   13u  IPv6 4376105      0t0  TCP *:1338 (LISTEN)
root@therms-app-sandbox:~# pm2 list
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ App name โ”‚ id โ”‚ mode โ”‚ pid โ”‚ status โ”‚ restart โ”‚ uptime โ”‚ memory โ”‚ watching โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
 Use `pm2 show <id|name>` to get more details about an app
root@therms-app-sandbox:~# 

i'm logged in as root and the running pm2 process was started by root in a different session... any explanation?

Getting the same issue as you @crobinson42

Setup npm and node ad root
Installed pm2 globally as root
Post deploy commands are executed with sudo

I can see the app list showing on the terminal the deploy is executed but as soon as I log into the server and gain sudo privilegies Y can not see any app on the list.

You likely launched your apps with a different PM2_HOME location.

Check to see where you have pm2 daemons running:

$ sudo ps aux | grep pm2

Chances are you have more than one, e.g.:

PM2 v2.0.18: God Daemon (/etc/.pm2)
PM2 v2.0.18: God Daemon (/home/root/.pm2)

The daemon that is running your applications will have .pid files in PM2_HOME/pids. Find out which one that is (probably /etc/.pm2/pids).

Then set the PM2_HOME variable and try again:

$ sudo PM2_HOME=/etc/.pm2 pm2 list

You'll probably want to relocate your apps to run from a PM2_HOME other than /etc/.pm2

I have a problem with PM2 when running my app; As I am new node developer may my steps to run app looks funny :)
I follow below steps to run my app:

After uploading code to server I use pm2 start app.js -n "appname" to run project;
By pm2 list I could see information of project also after logout and log in to server and for some days

BUT the main problem is long time running! My project stops after some days running (about 4 days)
Why it stops? (no exception has been logged) and How can I prevent project to stop running;
In other way can I run project just after stopping?

@FaShapouri PM2 might run out of memory and somethings like this, could you check ~/.pm2/pm2.log for errors ?

@vmarchaud Sorry I have just seen your answer, I got the permission denied when try ~/.pm2/pm2.log command. Is it unusual?

@FaShapouri Shouldn't be the case, that mean that your daemon is launched with another user (root in this case) and you don't have access to his log (so you can't access it too), try to fix that.

@vmarchaud I have two users to login on server and my current user is not limited also I run pm2 by this user; OK I found at first step I need to have this log; I try to get it.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ldarren picture ldarren  ยท  3Comments

psparago picture psparago  ยท  3Comments

chaos-git picture chaos-git  ยท  3Comments

cchan picture cchan  ยท  3Comments

webchaz picture webchaz  ยท  3Comments