Django app is always suspended after deployment

Hi, I’m new to fly, but I have a django app that I’m trying to deploy. I can run launch and deploy with no difficulty, but when I go to the URL nothing shows up, and the dashboard says the site is suspended after a few minutes. Nothing in the shell suggests that anything went wrong, but something is causing all of my machines to restart until they reach their limit. The app runs fine locally with manage.py runserver, so it shouldn’t be problem with my code. Nothing jumps out to me in the logs, but I’ll paste them below. Would appreciate any help, let me know if you need more files and I’ll paste them

$ fly logs -a discuss-it

Waiting for logs…

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] value.contribute_to_class(cls, name)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/models/options.py”, line 231, in contribute_to_class

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] self.db_table, connection.ops.max_name_length()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/utils/connection.py”, line 15, in getattr

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return getattr(self._connections[self._alias], item)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/utils/connection.py”, line 62, in getitem

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] conn = self.create_connection(alias)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/utils.py”, line 193, in create_connection

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] backend = load_backend(db[“ENGINE”])

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/utils.py”, line 113, in load_backend

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return import_module(“%s.base” % backend_name)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/importlib/init.py”, line 127, in import_module

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return _bootstrap._gcd_import(name[level:], package, level)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py”, line 28, in

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] raise ImproperlyConfigured(“Error loading psycopg2 module: %s” % e)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named ‘psycopg2’

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] [2023-11-26 13:59:14 +0000] [312] [ERROR] Exception in worker process

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] Traceback (most recent call last):

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py”, line 24, in

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] import psycopg2 as Database

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] ModuleNotFoundError: No module named ‘psycopg2’

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] During handling of the above exception, another exception occurred:

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] Traceback (most recent call last):

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py”, line 609, in spawn_worker

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] worker.init_process()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py”, line 134, in init_process

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] self.load_wsgi()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py”, line 146, in load_wsgi

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] self.wsgi = self.app.wsgi()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py”, line 67, in wsgi

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] self.callable = self.load()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py”, line 58, in load

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return self.load_wsgiapp()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py”, line 48, in load_wsgiapp

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return util.import_app(self.app_uri)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/gunicorn/util.py”, line 371, in import_app

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] mod = importlib.import_module(module)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/importlib/init.py”, line 127, in import_module

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return _bootstrap._gcd_import(name[level:], package, level)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 1014, in _gcd_import

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 991, in _find_and_load

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 975, in _find_and_load_unlocked

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 671, in _load_unlocked

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 843, in exec_module

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 219, in _call_with_frames_removed

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/code/mysite/wsgi.py”, line 16, in

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] application = get_wsgi_application()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/core/wsgi.py”, line 12, in get_wsgi_application

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] django.setup(set_prefix=False)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/init.py”, line 24, in setup

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] apps.populate(settings.INSTALLED_APPS)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/apps/registry.py”, line 116, in populate

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] app_config.import_models()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/apps/config.py”, line 269, in import_models

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] self.models_module = import_module(models_module_name)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/importlib/init.py”, line 127, in import_module

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return _bootstrap._gcd_import(name[level:], package, level)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 1014, in _gcd_import

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 991, in _find_and_load

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 975, in _find_and_load_unlocked

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 671, in _load_unlocked

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 843, in exec_module

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “”, line 219, in _call_with_frames_removed

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/code/core/models.py”, line 2, in

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] from django.contrib.auth.models import User # new

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/contrib/auth/models.py”, line 3, in

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/contrib/auth/base_user.py”, line 49, in

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] class AbstractBaseUser(models.Model):

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/models/base.py”, line 141, in new

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] new_class.add_to_class(“_meta”, Options(meta, app_label))

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/models/base.py”, line 369, in add_to_class

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] value.contribute_to_class(cls, name)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/models/options.py”, line 231, in contribute_to_class

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] self.db_table, connection.ops.max_name_length()

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/utils/connection.py”, line 15, in getattr

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return getattr(self._connections[self._alias], item)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/utils/connection.py”, line 62, in getitem

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] conn = self.create_connection(alias)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/utils.py”, line 193, in create_connection

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] backend = load_backend(db[“ENGINE”])

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/utils.py”, line 113, in load_backend

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return import_module(“%s.base” % backend_name)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/importlib/init.py”, line 127, in import_module

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] return _bootstrap._gcd_import(name[level:], package, level)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] File “/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/base.py”, line 28, in

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] raise ImproperlyConfigured(“Error loading psycopg2 module: %s” % e)

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named ‘psycopg2’

2023-11-26T13:59:14.812 app[4d89de9ea29d38] bos [info] [2023-11-26 13:59:14 +0000] [313] [INFO] Worker exiting (pid: 313)

2023-11-26T13:59:14.813 app[4d89de9ea29d38] bos [info] [2023-11-26 13:59:14 +0000] [312] [INFO] Worker exiting (pid: 312)

2023-11-26T13:59:15.101 app[4d89de9ea29d38] bos [info] [2023-11-26 13:59:15 +0000] [306] [ERROR] Worker (pid:312) exited with code 3

2023-11-26T13:59:15.105 app[4d89de9ea29d38] bos [info] [2023-11-26 13:59:15 +0000] [306] [ERROR] Worker (pid:313) was sent SIGTERM!

2023-11-26T13:59:15.208 app[4d89de9ea29d38] bos [info] [2023-11-26 13:59:15 +0000] [306] [ERROR] Shutting down: Master

2023-11-26T13:59:15.208 app[4d89de9ea29d38] bos [info] [2023-11-26 13:59:15 +0000] [306] [ERROR] Reason: Worker failed to boot.

2023-11-26T13:59:16.013 app[4d89de9ea29d38] bos [info] INFO Main child exited normally with code: 3

2023-11-26T13:59:16.014 app[4d89de9ea29d38] bos [info] INFO Starting clean up.

2023-11-26T13:59:16.015 app[4d89de9ea29d38] bos [info] WARN hallpass exited, pid: 307, status: signal: 15 (SIGTERM)

2023-11-26T13:59:16.020 app[4d89de9ea29d38] bos [info] 2023/11/26 13:59:16 listening on [fdaa:3:3c65:a7b:1ed:a7eb:77de:2]:22 (DNS: [fdaa::3]:53)

2023-11-26T13:59:17.017 app[4d89de9ea29d38] bos [info] [ 4.294466] reboot: Restarting system

2023-11-26T13:59:17.143 runner[4d89de9ea29d38] bos [info] machine has reached its max restart count (10)

it looks like you may not be installing all of the expected python modules. do you have the ability to test the container image you’re building works against postgres?

Thank you so much for replying! You were right that postgres is the problem, I tried relaunching without using the postgres database and the site is up now. The problem is that I need a backend for my site, and so it still isn’t functional. Is there another way to make a dynamic site work with fly, or is there some way to figure out what specific things might be interfering with postrges?

I don’t to much (really, any) development with Python but there should be steps in the Dockerfile to install the various Python dependencies so the modules would be available to use by the application.

something like:

COPY requirements.txt ./
RUN pip install -r requirements.txt

there would still need to be postgres somewhere the application has access to (either deployed to fly or supabase, neon, aws, etc.)

Ok, that makes sense. I actually found out the issue was just that I hadn’t migrated my libraries in the actual deployment. I had to ssh into it and run fly ssh console --pty -C “python /code/manage.py migrate” to get it to work. Thanks for your help!