Hi. I followed Using PM2 in Cloud Providers and deployed to AWS Elastic Beanstalk successfully. But my problem is, when I run command like pm2 monit, bash tell me that pm2: command not found. I've tried something like the following but in vain:
PATH=$PATH:`ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin
pm2 list in this folder, but got an empty list:ec2-user@ip-10-153-160-238 ~]$ /var/app/current/node_modules/pm2/bin/pm2 list
โโโโโโโโโโโโฌโโโโโฌโโโโโโโฌโโโโโโฌโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโฌโโโโโโโโโโโ
โ App name โ id โ mode โ pid โ status โ restart โ uptime โ memory โ watching โ
โโโโโโโโโโโโดโโโโโดโโโโโโโดโโโโโโดโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโดโโโโโโโโโดโโโโโโโโโโโ
Use `pm2 show <id|name>` to get more details about an app
What should I do to make it work? Thanks.
try node_modules/.bin/pm2 monit instead of pm2 monit
looks like you didn't install your pm2 globally, which is fine, but your bash doesn't know to look into node_modules/bin
I've tried /var/app/current/node_modules/pm2/bin/pm2 list but got an empty list.
I had the same issue and it looks like the problem is to do with how PM2 starts up. My problem was that i was using the AWS EB interface to set the node command e.g. npm run serve which in turn would run pm2 start.... After some debugging, I realised that pm2 was being started by the nodejs user instead of ec2-user and thats the reason why i was getting an empty list, because the user was wrong.
In order to see the apps running I had to run the following command:
sudo -u nodejs pm2 list
sudo -u nodejs pm2 list Works for me too. Thank you @antonsamper!
I know that the thread already closed, but may this will save time for the next one that will google it:
sudo -u nodejs /opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/node /var/app/current/node_modules/.bin/pm2 monit
Amazon Elastic Beanstalk environment, 64bit Amazon Linux 2016.09, pm2 installation according to this guide, e.g.
"scripts": {
"start": "node ./node_modules/.bin/pm2 start app.js --name yourApp",
"poststart": "node ./node_modules/.bin/pm2 logs"
}
@antonsamper What was the command then to start pm2? I understand then that it would be this
sudo -u nodejs node ./node_modules/.bin/pm2 start app.js
i have 502 bad gateway and i have aws eb
You should make sure that node is in your PATH.
If not you should specify the full path, something like /opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/node
@ArMouReR is right, it sounds like a PATH issue.
I get around this PATH issue by binding the PATH straight away with .ebextensions where i have the following lines:
yaml
container_commands:
01_pm2_install:
command: "if [ ! -e /bin/pm2 ]; then npm install [email protected] -g; fi"
02_pm2_binary:
command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/pm2 /bin/pm2"
This is what I used
sudo ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-* | head -1`/bin/node /bin/node
sudo -u nodejs node /var/app/current/node_modules/.bin/pm2 list
Most helpful comment
I know that the thread already closed, but may this will save time for the next one that will google it:
sudo -u nodejs /opt/elasticbeanstalk/node-install/node-v6.10.0-linux-x64/bin/node /var/app/current/node_modules/.bin/pm2 monitAmazon Elastic Beanstalk environment, 64bit Amazon Linux 2016.09, pm2 installation according to this guide, e.g.
"scripts": { "start": "node ./node_modules/.bin/pm2 start app.js --name yourApp", "poststart": "node ./node_modules/.bin/pm2 logs" }