Is there a way to get the replica ID from an environment variable or otherwise?

I want to set up a pager to the different replicas of my app server. Was wondering if it's possible to get a replica ID local to the machine and include that in the ping to Uptime Kuma.
16 Replies
Percy
Percy5mo ago
Project ID: 29a5fb27-3661-4597-af03-ec799c4720cd
Deani1232
Deani12325mo ago
29a5fb27-3661-4597-af03-ec799c4720cd
Fragly
Fragly5mo ago
yes, you're looking for the RAILWAY_REPLICA_ID service variable
Deani1232
Deani12325mo ago
Neat, thank you. Do you know if this stays the same across restart/redeployment or does it change?
Brody
Brody5mo ago
link the docs fragly!! but that variable will change every deployment
Deani1232
Deani12325mo ago
See it now. Probably should update the replica docs as well to include a mention to that maybe.
Brody
Brody5mo ago
good suggestion
Deani1232
Deani12325mo ago
I'm guessing there's no way to route to a specific replica for these health checks, right? Like can I ping via port or something to a specific one?
Brody
Brody5mo ago
well what do you want to do exactly? check if all replicas are alive?
Deani1232
Deani12325mo ago
Yeah. One of them drops out periodically and it comes back alive but the pager only hits one at a time and bc it's round-robin, it can hit the same ones multiple times. I'm guessing I need to create a central server that waits for pings from each replica ID and then pings the uptime checker. Was trying to be lazy and not do that.
Brody
Brody5mo ago
maybe write a simple inbetween app to do a dns lookup and then ping each ip example https://utilities.up.railway.app/dns-lookup?value=hello-world.railway.internal&type=ip my hello-world service is running 5 replicas
Deani1232
Deani12325mo ago
value in the url string is the railway domain?
Brody
Brody5mo ago
yeah thats the internal domain of course, this is just an example lookup for the domains AAAA value
Deani1232
Deani12325mo ago
Gotcha. Not a problem I can solve today, but this seems like the best move.
Brody
Brody5mo ago
kinda sounds like a fun little app to write