Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically restart dev backend in case of errors #408

Merged
merged 2 commits into from
Feb 4, 2024
Merged

Conversation

Aketzu
Copy link
Contributor

@Aketzu Aketzu commented Feb 3, 2024

No description provided.

@japsu
Copy link
Contributor

japsu commented Feb 3, 2024

If it only were this simple.

I could live with the restart loop this causes in the backend. While it burns a lot of CPU cycles and electricity and heats my lap up, it's not a critcal flaw of this approach.

However, because we have frontend and minio specify network_mode: service:backend, that will fail if the container of backend dies and is brought back up: it will have its own, new network namespace while the frontend and minio containers will be stuck in the network namespace of the old, dead backend container. This breaks browser access to frontend at localhost:3000, and access of frontend to backend at localhost:8000 (minio simil.).

This could be worked around by adding a router container that is basically sleep infinity and exports port 3000, 8000 and 9000, and setting network_mode: service:router in backend (new!), frontend and minio. While that would still leave the restart loop, it would be an improvement to current situation in which I need to docker compose up -d backend manually.

A preferrable solution would be to handle this in python manage.py docker_start. If it notices runserver exit non-zero, it would enter a waiting state, and when there is a change in any file under /usr/src/app (watchdog or something), execute runserver again.

One option would be to co-opt Django's own watcher but have it watch a null process instead of runserver. This was discussed in the original Slack thread. Viability unknown.

@Aketzu
Copy link
Contributor Author

Aketzu commented Feb 4, 2024

There is depends_on which automatically restarts containers except when the service fails by itself...

v2 with separate router container which exposes ports so backend and frontend can restart as they want. Still burns bunch of CPU cycles but "it works" at least to some degree.

@japsu japsu merged commit 0ff286c into con2:main Feb 4, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants