Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use PM2 CLI on Heroku

I'm trying to use pm2 on Heroku. I did have a look at the documentation. It looks like the application works fine once deployed, and the logs indicates that multiple instances has started on a 2X dyno.

Yet when I run: heroku run bash and do a pm2 ls I get an empty list:

┌──────────┬────┬──────┬─────┬────────┬─────────┬────────┬────────┬──────────┐
│ App name │ id │ mode │ pid │ status │ restart │ uptime │ memory │ watching │
└──────────┴────┴──────┴─────┴────────┴─────────┴────────┴────────┴──────────┘

And I can't use any pm2 CLI functions. I understand that when I do a heroku run command a one-off dyno is created on the fly and the pm2 instance running on this dyno does not run any process.

However I don't see how I can access pm2 on a specific dyno.

Is there any way to take advantage of the pm2 cli on Heroku?

like image 668
adc06 Avatar asked Aug 25 '15 14:08

adc06


2 Answers

heroku run connects you to an additional temporary container.

To connect to a real running app container, use heroku ps:exec.

like image 50
Alexander Zinchuk Avatar answered Oct 21 '22 04:10

Alexander Zinchuk


As mentioned in the Heroku docs,

your app is spread across many dynos

As a result there isn't one place your app is running so I can't see how you will be able to do what you want.

Heroku's docs explain this a bit more.

like image 4
Alex Chesters Avatar answered Oct 21 '22 03:10

Alex Chesters