Reputation: 2847
I am trying to configure gunicorn and supervisor for Django. I have configured gunicorn and i can run the django app using gunicorn manually. Now i have tried to configure the supervisor, the issue is that gunicorn process is not being started on instance restart. If i start the app from supervisorctl manually then app will start running. When i see status in supervisorctl, it is FATAL and stderr says
Traceback (most recent call last):
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 75, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/base.py", line 189, in run
super(Application, self).run()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/arbiter.py", line 114, in setup
self.app.wsgi()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 66, in load
return self.load_wsgiapp()
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/gunicorn/util.py", line 355, in import_app
__import__(module)
ImportError: No module named 'config'
django app structure
subscription-project \
.codeintel
.ebextensions
.git
.gitignore
Makefile
Procfile
README.rst
common
config \
__init__.py
settings
urls.py
wsgi.py
djangoapps
locale
manage.py
requirements
runtime.txt
subscriptionapp_gunicorn.py
import multiprocessing
preload_app = True
timeout = 300
bind = "127.0.0.1:8000"
pythonpath = "/subscription/app/subscriptionapp/subscription-project"
workers = (multiprocessing.cpu_count()-1)
upstart supervisor config (/etc/init/supervisor.conf)
description "supervisord"
start on runlevel [2345]
stop on runlevel [!2345]
kill timeout 432000
setuid www-data
exec /subscription/app/supervisor/venvs/supervisor/bin/supervisord -n --configuration /subscription/app/supervisor/supervisord.conf
/subscription/app/supervisor/conf.d/subscriptionapp.conf
[program:subscriptionapp]
command=/subscription/app/subscriptionapp/venvs/subscriptionapp/bin/gunicorn -c /subscription/app/subscriptionapp/subscriptionapp_gunicorn.py config.wsgi
user=www-data
directory=/subscription/app/subscriptionapp/subscription-project
environment=PORT=8000,ADDRESS=127.0.0.1,LANG=en_US.UTF-8,DJANGO_SETTINGS_MODULE=config.settings.base,PATH="/subscription/app/subscriptionapp/venvs/subscriptionapp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
stdout_logfile=/subscription/var/log/supervisor/subscriptionapp-stdout.log
stderr_logfile=/subscription/var/log/supervisor/subscriptionapp-stderr.log
killasgroup=true
stopasgroup=true
supervisord.conf
; supervisor config file
[unix_http_server]
file=/subscription/var/supervisor/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/subscription/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/subscription/var/supervisor/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/subscription/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:///subscription/var/supervisor/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.
[inet_http_server]
port = 127.0.0.1:9001
[include]
files = /subscription/app/supervisor/conf.d/*.conf
Any help to resolve the issue will be highly appreciated.
Upvotes: 1
Views: 537
Reputation: 10850
It seems the config
package is not available to gunicorn. Try explicitly adding the project directory to pythonpath like so:
[program:subscriptionapp]
command=/subscription/app/subscriptionapp/venvs/subscriptionapp/bin/gunicorn -c /subscription/app/subscriptionapp/subscriptionapp_gunicorn.py --pythonpath '/subscription/app/subscriptionapp/subscription-project,/subscription/app/subscriptionapp/venvs/subscriptionapp/lib/python3.4/site-packages/' config.wsgi
user=www-data
directory=/subscription/app/subscriptionapp/subscription-project
environment=PORT=8000,ADDRESS=127.0.0.1,LANG=en_US.UTF-8,DJANGO_SETTINGS_MODULE=config.settings.base,PATH="/subscription/app/subscriptionapp/venvs/subscriptionapp/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
stdout_logfile=/subscription/var/log/supervisor/subscriptionapp-stdout.log
stderr_logfile=/subscription/var/log/supervisor/subscriptionapp-stderr.log
killasgroup=true
stopasgroup=true
If this helps gunicorn to "find" config
, if may be your gunicorn configuration file is not being loaded properly. Depending on your gunicorn version, loading settings from a python module may require a special form, as in docs:
Changed in version 19.4: Loading the config from a Python module requires the python: prefix.
Upvotes: 0