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.