2 months ago
I can't get the healthcheck setting to work. I have a /health endpoint that currently works in the deployment:
❯ curl -s -w "\n%{http_code}\n" https://shopify-data-pipeline-production.up.railway.app/health
{"status":"ok"}
200
However when I add the health check option the server deployment fails (due to the healtcheck). I have tried the following values for the setting without success:
/health
health
https://shopify-data-pipeline-production.up.railway.app/health
http://localhost:5001/health
What is the correct way to set this up?
15 Replies
2 months ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
2 months ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • 2 months ago
2 months ago
The correct way to use the healthcheck on Railway is specifying the path not the URL. Meaning you'd want /health and not health or https://shopify-data-pipeline-production.up.railway.app/health
What host is your app listening on?
2 months ago
/health is what you should be using.
Can you share the entire deployment logs with it set to this?
2 months ago
This typically happens when your application is binding to localhost or 127.0.0.1 instead of 0.0.0.0
Check your application's host binding. Your app needs to listen on 0.0.0.0 (all interfaces) rather than localhost or 127.0.0.1
Verify your PORT environment variable. Railway provides a PORT environment variable
Check your deployment logs for any startup errors or binding messages that might indicate the actual issue.
2 months ago
If their application were bound to localhost or 127.0.0.1 we would not be able to access it on the web. That is not the issue.
2 months ago
2 months ago
Hmmm… Locally if you make a request to the health endpoint does it go through and work?
kafkasl
Yes it does!
2 months ago
And just to repeat myself one more time... do you have a variable named PORT set to be 5001?
2 months ago
kafkasl
I am unsure where this variable should be because it's already set in the networking and the dockerfile (see images below). Not sure where do I actually need the variable. Afaict railway itself is setting that to 5001.
2 months ago
(When I say None in this response I mean null, however that applies in Dockerfile or Python.)
Railway's healthcheck uses the PORT variable. It doesn't look at anything else, and it uses the internal IP. Try making a variable named PORT and setting it to 5001, as well as changing your host in that Dockerfile to be None. Changing your host to that ensures that Railway can access it over IPv6, and adding the port variable ensures that Railway knows where to look.
⠀
TLDR:
Add PORT variable with value 5001.
Change host in your start command to be None.
2 months ago
Recently fixed this same issue here: https://station.railway.com/questions/unable-resolve-health-check-b9f3ba3d#x0kj
Please let me know if this fixes yours as well.
2 months ago
I managed to fix it, there's more than one combination that works so here's the list:
1) Add manually PORT variable with 5001 . I thought that railway picked that up already from the networking, where they already ask you which port the app is in, but it seems you need to manually add it anyway. Creating the var inside the Dockefile won't work either.
Depending on whether you want to run uvicorn or python as start command you do:
2a) Python
CMD ["python", "main.py"] and in main.py
if __name__ == '__main__': import uvicorn port = int(os.getenv('PORT', 5001)) uvicorn.run("main:app", host=None, port=port)
2b) Uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "5001"] inside main.py you don't need to do anything.
What did NOT work for me:
CMD ["uvicorn", "main:app", "--host", "::", "--port", "5001"] CMD ["uvicorn", "main:app", "--host", "", "--port", "5001"] CMD ["uvicorn", "main:app", "--host", "''", "--port", "5001"] uvicorn.run("main:app", port=port)uvicorn.run("main:app", host='', port=port)samgordon
(When I say None in this response I mean null, however that applies in Dockerfile or Python.)Railway's healthcheck uses the PORT variable. It doesn't look at anything else, and it uses the internal IP. Try making a variable named PORT and setting it to 5001, as well as changing your host in that Dockerfile to be None. Changing your host to that ensures that Railway can access it over IPv6, and adding the port variable ensures that Railway knows where to look.⠀TLDR:Add PORT variable with value 5001.Change host in your start command to be None.
2 months ago
None needs to be 0.0.0.0 when running uvicorn as a command, and None when doing it from python.
Status changed to Solved ray-chen • 2 months ago

