keymetrics / pm2-plus-tech-questions

http://docs.keymetrics.io/docs/pages/faq-troubleshooting/
27 stars 3 forks source link

Using pm2 on bun+express server hosted on Railway.app #325

Open i8ramin opened 5 months ago

i8ramin commented 5 months ago

Hello, we are trying to add pm2 to our existing bun+express server running on Railway.app but having some issues with the setup and configuration. It all seems to be working fine locally, but when deployed to Railway, even though it looks like the process is running, it does not seem to start the server properly (daemon vs runtime maybe?)

Here are the logs from Railway.app when our server is deployed using pm2 to start it:

The contents of our ecosystem.config.js

module.exports = {
  apps: [
    {
      name: 'api',
      script: './dist/api',
      max_memory_restart: '2G',
      max_restarts: 5,
      min_uptime: 10000, // 10s
    },
  ],
}

package.json build and start commands:

"scripts": {
  "build": "bun build --compile --sourcemap --target node ./src/index.ts --outfile dist/api",
  "start": "pm2 start ecosystem.config.js",
}
$ turbo run start --filter={apps/api} --log-prefix=none
• Packages in scope: api
• Running start in 1 packages
• Remote caching disabled
cache bypass, force executing b341b82a7158b9fd
$ pm2 start ecosystem.config.js
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2 I/O] Using: Public key: ********** | Private key: ********* | Machine name: railway-1a6d
[PM2] PM2 Successfully daemonized
[PM2][WARN] Applications api not running, starting...
[PM2] App [api] launched (1 instances)
┌────┬────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name   │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ api    │ default     │ 0.0.0   │ fork    │ 120      │ 0s     │ 0    │ online    │ 0%       │ 69.7mb   │ root     │ disabled │
└────┴────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Tasks:    1 successful, 1 total
Cached:    0 cached, 1 total
Time:    5.505s

Interestingly, I see different output locally when I issue the same pm2 start ecosystem.config.js. It does not spawn. This is what I see when I run it locall:

❯ bun run api:start
$ turbo run start --filter={apps/api} --log-prefix=none
• Packages in scope: api
• Running start in 1 packages
• Remote caching disabled
cache bypass, force executing 8fdb02bc04a8e144
$ pm2 start ecosystem.config.js
[PM2][WARN] Applications api.dupe.com not running, starting...
[PM2] App [api.dupe.com] launched (1 instances)
⇆ PM2+ activated | Instance Name: MacBook-Pro-2.local-b5dc | Dash: https://app.pm2.io/#/r/auh2crryn6h1ern
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0  │ api.dupe.com       │ fork     │ 0    │ online    │ 0%       │ 12.1mb   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

 Tasks:    1 successful, 1 total
Cached:    0 cached, 1 total
  Time:    183ms