Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS EC2, pm2 : Cannot see pm2 running list

I'm using Amazon Linux AMI 2017.03.1 (HVM), SSD Volume Type.

And I installed node.js, npm via the way like this below because I want to install globally and if I don't install pm2 globally, it doesn't work when I configure EC2 bootstrapping launching pm2 command.

After that I created my own AMI image.

### node.js, npm install ###
  $ sudo su
  $ curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
  $ yum -y install nodejs
### pm2 install ###
   $ npm install pm2 -g

and here is my user-data text at 'Advanced Details' when i create new EC2 instance via my own AMIs.

### user-data ###
 #!/bin/bash
 cd /home/ec2-user/Node.js-Test
 sudo git pull origin master
 export PM2_HOME=/home/ec2-user/
 sudo env PATH=$PATH:/usr/bin/ pm2 startup systemv -u ec2-user --hp /home/ec2-user
 su ec2-user
 pm2 start /home/ec2-user/Node.js-Test/app.js
 pm2 save

so when I launch new EC2 instance with this configuration above, pm2 command is working but I cannot see the running pm2 list.

When I checked the log file /var/log/cloud-init-output.log, it has info of running pm2 application!

### /var/log/cloud-init-output.log ###
 [PM2] Spawning PM2 daemon with pm2_home=/home/ec2-user/
 [PM2] PM2 Successfully daemonized
 [PM2] Starting /home/ec2-user/Node.js-Test/app.js in fork_mode (1 instance)
 [PM2] Done.
 ┌─────────────────────────────────────────────────────────────────────────────────────────────┐
 │ App name │ id │ mode │ pid  │ status │ restart │ uptime │ cpu │ mem        │ user │ watching │
 ├──────────────────────────────────────────────────────────────────────────────────────────────
 │ app       │ 0  │ fork │ 2677 │ online │ 0        │ 0s      │ 99% │ 15.4 MB   │ root │ disabled │
 └─────────────────────────────────────────────────────────────────────────────────────────────┘
  Use 'pm2 show <id|name>' to get more details about an app

but I cannot see that running pm2 list @ec2-user, @root

### in terminal EC2 instance ###
 [ec2-user@ip-172-31-10-85 ~]$ pm2 list
 ┌──────────────────────────────────────────────────────────────────────────────────────┐
 │ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
 └──────────────────────────────────────────────────────────────────────────────────────┘
 Use 'pm2 show <id|name>' to get more details about an app
 [ec2-user@ip-172-31-10-85 ~]$ sudo su
 [root@ip-172-31-10-85 ec2-user]# pm2 list
 ┌──────────────────────────────────────────────────────────────────────────────────────┐
 │ App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │
 └──────────────────────────────────────────────────────────────────────────────────────┘
  Use 'pm2 show <id|name>' to get more details about an app

Does anyone who know this issue and solution??? Thanks.

like image 520
geoseong Avatar asked Sep 01 '17 06:09

geoseong


1 Answers

I changed several commands in EC2 User-Data like

#!/bin/bash
cd /home/ec2-user/Node.js-Test
sudo git pull origin master
sudo pkill -f PM2
sudo pm2 start /home/ec2-user/Node.js-Test/app.js
sudo pm2 startup
sudo pm2 save

and I can see pm2 list now typing sudo -i pm2 list. and shown empty list when i just typed pm2 list.

[ec2-user@ip-172-31-14-68 .pm2]$ sudo pm2 list
┌──────────┬────┬──────┬──────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
│ App name │ id │ mode │ pid  │ status │ restart │ uptime │ cpu │ mem       │ user │ watching │
├──────────┼────┼──────┼──────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
│ app      │ 0  │ fork │ 2458 │ online │ 0       │ 11m    │ 0%  │ 29.3 MB   │ root │ disabled │
└──────────┴────┴──────┴──────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘

And here is context of /root/.pm2/dump.pm2.

https://github.com/geoseong/Node.js-Test/blob/master/pm2/dump_pm2_sudo_170904

hope it help for those who got the problem like this.

Thanks.

like image 69
geoseong Avatar answered Nov 17 '22 22:11

geoseong