Why does Daphne fail when starting supervisor, but works when launched from the command line?

I am trying to use supervisor to manage Daphne's server and multiple workers for a Django app on AWS. I followed this tutorial . My supervisord.conf looks like this:

; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0770                       ; socket file mode (default 0700)
chown=root:supervisor

[inet_http_server]
port = 9001
username = nte_user # Basic auth username
password = generated-passphrase # Basic auth password

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf

      

My custom config file is in /etc/supervisor/conf.d/company_name.conf and looks like this (I tried to get server_interface to work before I added workers):

[program:server_interface]
command=/home/web/venv/bin/daphne -b 127.0.0.1 -p 8000 company_name.asgi:channel_layer
directory=/home/web/api-server/company_name/
autostart=true
autorestart=true
stopasgroup=true
user=web

      

When I run this command: /home/web/venv/bin/daphne -b 127.0.0.1 -p 8000 company_name.asgi:channel_layer

from the command line while in /home/web/api-server/company_name/

, it works fine and the server starts up. When I run supervisorctl start server_interface

I see this output in the sdterr log:

2017-07-07 15:46:06,562 INFO     Starting new HTTP connection (1): 169.254.169.254
Traceback (most recent call last):
  File "/home/web/venv/bin/daphne", line 11, in <module>
    sys.exit(CommandLineInterface.entrypoint())
  File "/home/web/venv/local/lib/python2.7/site-packages/daphne/cli.py", line 125, in entrypoint
    cls().run(sys.argv[1:])
  File "/home/web/venv/local/lib/python2.7/site-packages/daphne/cli.py", line 155, in run
    channel_layer = importlib.import_module(module_path)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "./next-tier/asgi.py", line 6, in <module>
    channel_layer = get_channel_layer()
  File "/home/web/venv/local/lib/python2.7/site-packages/channels/asgi.py", line 98, in get_channel_layer
    django.setup(set_prefix=False)
  File "/home/web/venv/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/web/venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/web/venv/local/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "./stakeholder/models.py", line 18, in <module>
    from .managers import StakeholderManager, ContactInformationManager
  File "./stakeholder/managers.py", line 27, in <module>
    SURVEY_TABLE = DYNAMO_DB.Table(settings.SURVEY_TABLE_NAME)
  File "/home/web/venv/local/lib/python2.7/site-packages/boto3/resources/factory.py", line 474, in create_resource
    client=self.meta.client)(*args, **kwargs)
  File "/home/web/venv/local/lib/python2.7/site-packages/boto3/dynamodb/transform.py", line 32, in __init__
    super(DynamoDBHighLevelResource, self).__init__(*args, **kwargs)
  File "/home/web/venv/local/lib/python2.7/site-packages/boto3/dynamodb/table.py", line 30, in __init__
    super(TableResource, self).__init__(*args, **kwargs)
  File "/home/web/venv/local/lib/python2.7/site-packages/boto3/resources/base.py", line 119, in __init__
    'Required parameter {0} not set'.format(identifier))
ValueError: Required parameter name not set

      

The startup printenv

shows the required environment variable as set, as evidenced by the fact that Daphne starts normally from the command line, but I can't figure out why it won't start correctly when launched through Supervisor.

+3


source to share





All Articles