Django backend died when deploying a new version: Address already in use
1
vote
2
answers
97
views
I have a Django app running on a Debian server, with a simple deploy script that is automatically invoked via a GitHub webhook:
#!/bin/sh
git pull
/home/criticalnotes/.local/bin/poetry install --with prod --sync
/home/criticalnotes/.local/bin/poetry run ./manage.py migrate
sudo /usr/sbin/service api.critical-notes.com restart
echo "service api.critical-notes.com restarted"
So this deploy script pulls the latest code from git, installs the dependencies, runs the migrate script, and then restarts the service.
My api.critical-notes.com.service
file:
[Unit]
Description=api.critical-notes.com
[Service]
User=criticalnotes
Group=criticalnotes
Restart=on-failure
WorkingDirectory=/home/criticalnotes/api.critical-notes.com
ExecStart=/home/criticalnotes/.local/bin/poetry run uvicorn criticalnotes.asgi:application --log-level warning --workers 8 --uds /tmp/uvicorn.sock
[Install]
WantedBy=multi-user.target
This setup has worked perfectly fine for a pretty long time, but today when I pushed new code to GitHub the site stopped working. After looking into what was going on, I noticed that the api.critical-notes.com
service wasn't running any more, it kept dying with failures, and when trying to start the backend manually I got this error:
Address already in use
I have no idea what caused this problem, especially since this has never happened before and I have not made any deploy or setup changes today (or any time recently). So my question is how this could have happened - how could the address still be in use when the backend was not running? And secondly, how can I improve my deploy script so this can't happen again?
It was quite scary to have to site be offline because the backend was offline, for about 30 minutes while I was trying to figure out why my code push broke things. I don't want that to happen again 😅
Asked by Kevin Renskers
(61 rep)
Aug 5, 2023, 09:33 PM
Last activity: Aug 23, 2023, 09:46 AM
Last activity: Aug 23, 2023, 09:46 AM