adc06
adc06

Reputation: 793

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?

Upvotes: 10

Views: 2762

Answers (2)

Alexander Zinchuk
Alexander Zinchuk

Reputation: 855

heroku run connects you to an additional temporary container.

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

Upvotes: 2

Alex Chesters
Alex Chesters

Reputation: 3710

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.

Upvotes: 4

Related Questions