R
Railway•8mo ago
Limas

Multiple commands on start command won't work

I have a Django application for which I have a a Dockerfile, it works fine, but for a staging environment I wish to override the start command.
FROM python:3.10-slim-bullseye

ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code

COPY . .

RUN pip install -r requirements.txt

CMD gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm
FROM python:3.10-slim-bullseye

ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code

COPY . .

RUN pip install -r requirements.txt

CMD gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm
I created the following json to chain multiple commands including the sleep 3 to wait for the private DNS, but it only executes the first command, I already did a ton of tests, if I remove the sleep in the deployment logs I get to see only the migrate command output but the server doesn't execute the gunicorn. If I remove everything and only leave the gunicorn it works normally.
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "sleep 3 && python manage.py migrate && gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm",
"restartPolicyType": "NEVER",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "sleep 3 && python manage.py migrate && gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm",
"restartPolicyType": "NEVER",
"restartPolicyMaxRetries": 10
}
}
Solution:
when using a Dockerfile the start command you set either in the service settings or in the railway.json file is treated as an ENTRYPOINT meaning there is no shell running, && does not work without a shell, you would need to wrap your start command in a shell (thats what that syntax of CMD does)
/bin/sh -c "sleep 3 && python manage.py migrate && gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm"
/bin/sh -c "sleep 3 && python manage.py migrate && gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm"
...
Jump to solution
5 Replies
Percy
Percy•8mo ago
Project ID: 0583e1e9-1aa9-46ae-991c-5f8536d626c7
Limas
Limas•8mo ago
0583e1e9-1aa9-46ae-991c-5f8536d626c7
Solution
Brody
Brody•8mo ago
when using a Dockerfile the start command you set either in the service settings or in the railway.json file is treated as an ENTRYPOINT meaning there is no shell running, && does not work without a shell, you would need to wrap your start command in a shell (thats what that syntax of CMD does)
/bin/sh -c "sleep 3 && python manage.py migrate && gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm"
/bin/sh -c "sleep 3 && python manage.py migrate && gunicorn core.wsgi --workers=2 --threads=4 --worker-class=gthread --log-file=- --worker-tmp-dir /dev/shm"
Limas
Limas•8mo ago
Ahhhh TIL 🙂 thanks so much! It works.
Brody
Brody•8mo ago
no problem!
Want results from more Discord servers?
Add your server