a year ago
have a bun+express server running and trying to incorporate pm2 into the mix. I am able to get it working locally, but when I try to push the changes to Railway, it does not want to play nice.
This is what I see in the Railway Deploy Logs:
$ 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
The contents of my ecosystem.config.js
module.exports = {
apps: [
{
name: 'api',
script: './dist/api',
max_memory_restart: '2G',
max_restarts: 5,
min_uptime: 10000, // 10s
},
],
}
My api 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",
},
5 Replies
https://railway.app/project/7f34b4f7-9d09-48a8-997c-32a10e59c1eb/service/4ee59aa8-a293-4716-aaa6-c0183a0c468b?id=ef35ef07-cad2-46e1-8e30-709734fa97a9
a year ago
may I ask why you'd want to use pm2 on railway?
a year ago
a couple things to consider:
1 . Is your goal to use bun or node? You should pick one. Using different runtimes in development and production is adding an unnecessary layer of complexity that's also very hard to debug. dsespite what they tell you, bun is not a drop-in replacement for node (yet). I recommend sticking to node for now unless you have a practical understanding of what the differences between them are.
pm2 is also unnecessary complexity here, there are several other ways to accomplish the same task, the easiest of which is probably using cron and healthcheck features provided by railway for this purpose etc
a year ago
at the end of the day it sounds like you have an express app that you want to run on railway. none of the things causing you problems are necessary for that, just build it with node and deploy it normally
I should've said bun+express … we are using bun locally as well. Reasons I wanted to use pm2 was for its health & resource monitoring, and recovery mechanisms. I looked into integrating Datadog, but that seemed overly complicated with a separate hosted agent, and pm2 seemed like an easier solution. I guess APM is what I am looking for, along with continuous health checks + recovery. If there are better solutions that work well on Railway, I'm all ears!
a year ago
healthchecks: https://docs.railway.app/reference/healthchecks
restarts: https://docs.railway.app/guides/healthchecks-and-restarts
cron: https://docs.railway.app/reference/cron-jobs
all of these things are first class features on railway. once you deploy a service, there's a lot you can do if you click on it and go through all the stuff available there.
thank you for these links. and as far as APM and monitoring (beyond what Railway offers), any recommendations? The 2 that I am aware of (and now 3, pm2) are Datadog and NewRelic
a year ago
keep in mind railway does not offer continuous health checks
Yes, realized that. We are using the railway restart service you wrote to perform hourly restarts "just in case" .. but continuous health checks would be nice
a year ago
it would definitely be nice to have
a year ago
at some point health checks give way to proper redundancy. if it's that sensitive to downtime i mean.
a year ago
handle exceptions in your code so your app throws less, and use the tools you mentioned for monitoring instead of disaster recovery
100% with you on that. I think we have the disaster recover part figured out at this point. just need more visibility and monitoring. Can I ask why pm2 is not a good idea on Railway? I'm mostly interested in its monitoring capabilities at this point.
a year ago
not saying it's bad, ive just never considered using it on railway. webhooks fire on platform events like a service deployment crashing and i handle things from there. railways graphql API is powerful and gives me everything i need.
may still be an unpopular opinion for now but for metrics i lean into OpenTelemetry and hand roll stuff to spit in a database. in the most extreme cases ill view those metrics in a Prometheus, but rarely.
when deploying sentry i used probably 10% of that platforms capabilities for 90% of the things i needed it to do. its great, even indispensable at scale. but if you don't need it, it feels like buying a refrigerator that doesn't fit inside your doorway or something
a year ago
i try to write failsafe code as possible, and then build redundancy around services that are super downtime sensitive, leaving very little monitoring or metrics gathering ever needed
a year ago
this is all just sharing my experience as another customer tho
a year ago
everything's a tradeoff and you know best for your project ofc
a year ago
so no pm2 support on railway? is that correct?
i'm inheriting a repo that uses pm2 and would like not to mess with it. not here to justify pm2 over any other solution
a year ago
Should you or should you not use pm2 on Railway aside, pm2 can work just fine on Railway if setup correctly.
a year ago
can you help me with how? i have pm2 installed locally and the project is running but not sure how to mirror that on railway deployment
a year ago
*installed globally locally
a year ago
I'm sorry but I have not personally set it up myself, I have only seen it integrated into other services that run on Railway just fine, such as the Directus docker image, it uses pm2 internally without issue.