doc-pm2 icon indicating copy to clipboard operation
doc-pm2 copied to clipboard

Heroku | Integration | PM2 Documentation

Open rmonnier9 opened this issue 7 years ago • 8 comments

https://pm2.io/doc/en/runtime/integration/heroku/

PM2 - Guide, References, Tutorials and Best Practices about PM2 and Node.js.

rmonnier9 avatar May 30 '18 14:05 rmonnier9

Why do we use pm2-runtime here? Looks like it cannot find config in the project root.

pm2-runtime start

error: missing required argument `app.js|json_file'

pm2 runs fine.

nikolay-borzov avatar Jul 24 '18 15:07 nikolay-borzov

@nikolay-borzov Why do we use pm2-runtime here? Looks like it cannot find config in the project root.

pm2-runtime start

error: missing required argument `app.js|json_file'

pm2 runs fine.

Did you successfully deployed to heroku?

maulberto3 avatar Aug 16 '18 03:08 maulberto3

I could deployed successfully to Heroku with pm2-runtime start index.js. Note: pm2 start index.js works ok with heroku local, but it doesn't when deployed. You need the pm2-runtime start index.js to deploy. Strange...

maulberto3 avatar Aug 16 '18 03:08 maulberto3

I was able to deploy to Heroku by specifying config pm2-runtime start ecosystem.config.js. As I understood calling pm2 second time duplicates processes. pm2-runtime restarts existing ones. I haven't found any description of pm2-runtime. Perhaps it's possible to add a help page for this

nikolay-borzov avatar Aug 16 '18 14:08 nikolay-borzov

I have the same problem with pm2-runtime. I've a simple server listening at port 4000, I've configured 4 instances. Below is the error I encounter: [2018-08-22T07:50:13.285Z] PM2 log: Launching in no daemon mode [2018-08-22T07:50:13.349Z] PM2 log: Starting execution sequence in -fork mode- for app name:node-webpack-babel-starter id:0 [2018-08-22T07:50:13.357Z] PM2 log: App name:node-webpack-babel-starter id:0 online [2018-08-22T07:50:13.361Z] PM2 log: Starting execution sequence in -fork mode- for app name:node-webpack-babel-starter id:1 [2018-08-22T07:50:13.367Z] PM2 log: App name:node-webpack-babel-starter id:1 online [2018-08-22T07:50:13.369Z] PM2 log: Starting execution sequence in -fork mode- for app name:node-webpack-babel-starter id:2 [2018-08-22T07:50:13.380Z] PM2 log: App name:node-webpack-babel-starter id:2 online [2018-08-22T07:50:13.391Z] PM2 log: Starting execution sequence in -fork mode- for app name:node-webpack-babel-starter id:3 [2018-08-22T07:50:13.411Z] PM2 log: App name:node-webpack-babel-starter id:3 online Example app listening on port 4000! Example app listening on port 4000! [2018-08-22T07:50:13.730Z] PM2 log: App [node-webpack-babel-starter] with id [2] and pid [22967], exited with code [1] via signal [SIGINT] [2018-08-22T07:50:13.733Z] PM2 error: Cancelling versioning data parsing [2018-08-22T07:50:13.734Z] PM2 log: Starting execution sequence in -fork mode- for app name:node-webpack-babel-starter id:2 Error: listen EADDRINUSE :::4000 at Server.setupListenHandle [as _listen2] (net.js:1335:14) at listenInCluster (net.js:1383:12) at Server.listen (net.js:1470:7) at Function.listen (/home/box/mien/webpack-node/node_modules/express/lib/application.js:618:24) at Object.listen (/home/box/mien/webpack-node/dist/webpack:/src/main.js:9:5) at webpack_require (/home/box/mien/webpack-node/dist/webpack:/webpack/bootstrap:22:1) at module.exports (/home/box/mien/webpack-node/dist/webpack:/webpack/bootstrap:74:1) at Object. (/home/box/mien/webpack-node/dist/backend.js:78:10) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) Example app listening on port 4000! [2018-08-22T07:50:13.754Z] PM2 log: App name:node-webpack-babel-starter id:2 online Error: listen EADDRINUSE :::4000

udayRedI avatar Aug 22 '18 02:08 udayRedI

[2018-08-22T07:50:13.349Z] PM2 log: Starting execution sequence in -fork mode- for app name:node-webpack-babel-starter id:0

Did you specify the number of instances and cluster mode? Just a wild guess. My config looks like this:

module.exports = {
  apps: [
    {
      name: 'reverse-proxy',
      script: 'index.js',
      exec_mode: 'cluster',
      instances: 'max',
      merge_logs: true,
      dependencies: ['pm2-intercom']
    }
  ]
};

Also

Error: listen EADDRINUSE :::4000

Means there is no way you can start multiple servers using the same port when using fork mode. Again it's just my guess.

nikolay-borzov avatar Aug 22 '18 08:08 nikolay-borzov

@nikolay-borzov , Your guess was pretty accurate. Thank you! Solved the problem.

udayRedI avatar Aug 24 '18 01:08 udayRedI

Wouldn't it be best to also have a log configuration here to stdout for Heroku, so it's not filling up the filesystem and works with their logplex and and 12factor setup?

https://devcenter.heroku.com/articles/management-visibility#logging

niedfelj avatar Dec 06 '18 17:12 niedfelj