Deploy problem > Healthcheck always fails (PORT configured)
mfrancisca
HOBBYOP

2 months ago

Hello,

New to Railway here, so I'm sorry if this is a dumb question.

I have Django+Postgres application that I'm trying to deploy. The problem is with Django.All my deploy attempts are failing at the health check stage.

I have set the PORT variable manually to 3000, my Dockerfile exposes port 8000. On my railway.toml file I have this start command:

`startCommand = "python manage.py migrate --no-input && gunicorn config.wsgi --workers 2 --bind 0.0.0.0:8000 --error-logfile=- --access-logfile=- --log-level debug"'

I'm not sure what Im doing wrong. Is it the gunicorn command?

The deploy logs show the migration logs, but nothing on gunicorn. And there is no error logs anywhere that I can find.

Thanks for all the help

Solved$10 Bounty

14 Replies

Status changed to Open Railway about 2 months ago


domehane
FREE

2 months ago

Hello mfrancisca,

i noticed you have PORT set to 3000 in your variables but gunicorn is binding to 8000 , those two need to match so try changing your bind flag to --bind 0.0.0.0:$PORT and delete the manual PORT=3000 variable so railway assigns it automatically, that mismatch alone would cause the healthcheck to fail every time

Hope this help you :)


mfrancisca
HOBBYOP

2 months ago

I had it like that before and it was still happening (no PORT variable, gunicorn pointing to 8000, dockerfile exposing 8000).


domehane

Hello **mfrancisca**, i noticed you have PORT set to 3000 in your variables but gunicorn is binding to 8000 , those two need to match so try changing your bind flag to --bind 0.0.0.0:$PORT and delete the manual PORT=3000 variable so railway assigns it automatically, that mismatch alone would cause the healthcheck to fail every time Hope this help you :)

mfrancisca
HOBBYOP

2 months ago

I had it like that before and it was still happening (no PORT variable, gunicorn pointing to 8000, dockerfile exposing 8000).


domehane
FREE

2 months ago

okay do you have SECURE_SSL_REDIRECT = True in your django settings?


domehane

okay do you have SECURE\_SSL\_REDIRECT = True in your django settings?

mfrancisca
HOBBYOP

2 months ago

No, because my domain is behind cloudfare R2 and as far as I know setting SECURE_SSL_REDIRECT = True causes an infinite redirect loop? am I wrong?


domehane
FREE

2 months ago

okay now can you check if healthcheck.railway.app is in your django ALLOWED_HOSTS? railway's docs say their healthcheck requests come from that hostname


mfrancisca
HOBBYOP

2 months ago

I know I have not, I have my domain and .railway.app, let me add it and check


mfrancisca
HOBBYOP

2 months ago

Nup, still failing ☹ now I have my domain, healthcheck.railway.app and .up.railway.app. in ALLOWED_HOSTS


domehane
FREE

2 months ago

okay, can you share the full deploy logs


mfrancisca
HOBBYOP

2 months ago

Build logs:

[Region: us-east4]

=========================

Using Detected Dockerfile

=========================

context: zrpn-U_YE

internal

load build definition from Dockerfile.prod

1ms

internal

load metadata for docker.io/library/python:3.12-slim

154ms

auth

library/python:pull token for registry-1.docker.io

0ms

internal

load .dockerignore

0ms

1

FROM docker.io/library/python:3.12-slim@sha256:3d5ed973e45820f5ba5e46bd065bd88b3a504ff0724d85980dcd05eab361fcf4

7ms

internal

load build context

0ms

8

RUN useradd -m appuser && chown -R appuser /app cached

0ms

7

RUN DJANGO_SETTINGS_MODULE=config.settings.production SECRET_KEY=build-time-placeholder ALLOWED_HOSTS=localhost DATABASE_URL=postgres://placeholder:placeholder@localhost/placeholder AWS_ACCESS_KEY_ID=placeholder AWS_SECRET_ACCESS_KEY=placeholder AWS_STORAGE_BUCKET_NAME=placeholder AWS_S3_ENDPOINT_URL=https://placeholder.r2.cloudflarestorage.com python manage.py collectstatic --no-input cached

0ms

6

COPY . /app/ cached

0ms

5

RUN pip install --no-cache-dir -r requirements/base.txt cached

0ms

4

COPY requirements/base.txt /app/requirements/base.txt cached

0ms

3

RUN apt-get update && apt-get install -y libpq-dev gcc curl && rm -rf /var/lib/apt/lists/* cached

0ms

2

WORKDIR /app cached

0ms

auth

sharing credentials for production-us-east4-eqdc4a.railway-registry.com

0ms

importing to docker

7s

Build time: 8.95 seconds

==================== Starting Healthcheck ====================

Path: /robots.txt

Retry window: 5m0s

Attempt #1 failed with service unavailable. Continuing to retry for 4m49s

Attempt #2 failed with service unavailable. Continuing to retry for 4m38s

Attempt #3 failed with service unavailable. Continuing to retry for 4m26s

Attempt #4 failed with service unavailable. Continuing to retry for 4m12s

Attempt #5 failed with service unavailable. Continuing to retry for 3m54s

Attempt #6 failed with service unavailable. Continuing to retry for 3m28s

Attempt #7 failed with service unavailable. Continuing to retry for 2m48s

Attempt #8 failed with service unavailable. Continuing to retry for 2m8s

Attempt #9 failed with service unavailable. Continuing to retry for 1m28s

Attempt #10 failed with service unavailable. Continuing to retry for 48s

Attempt #11 failed with service unavailable. Continuing to retry for 8s

1/1 replicas never became healthy!

Healthcheck failed!

"

Deploy Logs:

"Starting Container

No migrations to apply.

Operations to perform:

Apply all migrations: auth, blog, contenttypes, pigments, sessions, taggit, wagtailadmin, wagtailcore, wagtaildocs, wagtailembeds, wagtailforms, wagtailimages, wagtailredirects, wagtailsearch, wagtailusers

Running migrations:"

Btw... how can I format text here so is a bit more legible? Looks like markdown format does not work?


domehane
FREE

2 months ago

okaay, logs show migrations run but gunicorn never starts (no gunicorn logs at all), so there is no server listening and healthcheck returns 503. since you are using a dockerfile, your startCommand is not executed in a shell, so "&&" is not interpreted and only the first command runs. that means only migrate runs and gunicorn is never executed. fix is to move migrate to predeploy command and keep startcommand only for gunicorn so the server actually starts


domehane

okaay, logs show migrations run but gunicorn never starts (no gunicorn logs at all), so there is no server listening and healthcheck returns 503\. since you are using a dockerfile, your startCommand is not executed in a shell, so "&&" is not interpreted and only the first command runs. that means only migrate runs and gunicorn is never executed. fix is to move migrate to predeploy command and keep startcommand only for gunicorn so the server actually starts

mfrancisca
HOBBYOP

2 months ago

What worked was to move migrate and gunicorn to Dockerfile under the CMD command, that fixed it. THank you for the help!


domehane
FREE

2 months ago

your welcome


mfrancisca

What worked was to move migrate and gunicorn to Dockerfile under the CMD command, that fixed it. THank you for the help!

domehane
FREE

2 months ago

glad it worked out yeah moving it to CMD in the dockerfile makes it cleaner and more reliable than chaining it in the start command. happy to help, don't forget to mark this as solved


Status changed to Solved mfrancisca 18 days ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...