0

I'm deploying a django/nginx/gunicorn site and am following this guide while doing so. Following the subheading "Final Steps for Production Deployments", I've created a production gunicorn configuration file and am running it from the command line with gunicorn -c config/gunicorn/prod.py. However, I've noticed that gunicorn will just... stop running, and I'm not sure why. (Worker timeout?)

I'd like to know the following:

  1. How to set gunicorn up so it keeps running so I don't have to log into prod and kick it,
  2. When gunicorn dies so I can set up an email alert, because 502s are bad,
  3. If I'm doing anything wrong.

I did initially attempt to follow this guide, but couldn't get it working with the socket for some reason. I suspect that's the longer-term answer, but again, couldn't get it up and running.

Here is my prod.py gunicorn conf:

import multiprocessing

wsgi_app = "config.wsgi:application"
loglevel = "info"
workers = multiprocessing.cpu_count() * 2 + 1
bind = "0.0.0.0:8000"
reload = True
accesslog = "/var/log/gunicorn/access.log"
errorlog = "/var/log/gunicorn/error.log"
capture_output = True
pidfile = "/var/run/gunicorn/prod.pid"
daemon = True
  • First, [show us](https://serverfault.com/posts/1119188/edit) the log with `loglevel='debug'` - info is not the maximum. Also, absolutely do get it setup to be launched & managed by a service manager (on Ubuntu, that would be systemd). `systemdctl status gunicorn.service` would definitely produce a consistent report, thats one of its main purposes, whereas you shells reports of what happened to subprocesses will me more crude. – anx Dec 31 '22 at 20:57
  • Have you looked into general system logs around the time? Memory pressure, which is easy to produce with postgresql settings not tailored to the system, might have lead to to kernel and/or userland OOM mechanisms. – anx Dec 31 '22 at 20:59
  • Can you add logs with more details. – asktyagi Jan 01 '23 at 06:32

1 Answers1

1

Check the logs: Gunicorn writes log messages to the console by default, so you should see any error messages or other useful information in the console output. You can also check the logs in your Django application by looking in the logs directory within your Django project directory.

Check for syntax errors in your configuration file: Make sure that your gunicorn configuration file is free of syntax errors. You can do this by running

python -m py_compile config/gunicorn/prod.py.

Check the permissions on your configuration file: Make sure that the user running gunicorn has permission to read the configuration file.

Check the processes: Make sure that gunicorn is the only process running. If there are multiple gunicorn processes running, it could cause issues. You can use the ps command to check for running processes, and the kill command to stop them.

Check your Django application for errors: It's possible that an error in your Django application is causing gunicorn to stop running. You can check for errors in your Django application by looking in the logs or by running the Django development server and accessing your application through a web browser.

njpdx
  • 86
  • 1