djangowebsocketdaphne

daphne run in supervisor returns an error django.core.exceptions.ImproperlyConfigured


why daphne returns an error to me via supervisor

django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure () before accessing settings.

But when I run it out of supervisorctl, it works. I have a system variable defined. Is it a mistake to run it in venv?.

supervisor conf

[fcgi-program:asgi]
# TCP socket used by Nginx backend upstream
socket=tcp://localhost:8099

# Directory where your site's project files are located
directory=/srv/app/

# Each process needs to have a separate socket file, so we use process_num
# Make sure to update "mysite.asgi" to match your project name
command=/srv/venv/bin/daphne -u /srv/run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers mysite.asgi:application

# Number of processes to startup, roughly the number of CPUs you have
numprocs=1

# Give each process a unique name so they can be told apart
process_name=asgi%(process_num)d

# Automatically start and recover processes
autostart=true
autorestart=true

# Choose where you want your log to go
stdout_logfile=/srv/log/daphne.log
redirect_stderr=true

Solution

  • I added to the conf [fcgi-program:asgi]

    environment=DJANGO_SETTINGS_MODULE=mysite.settings
    

    problem solved