Problems configuring deployment with Heroku/gunicorn/django

与世无争的帅哥 提交于 2020-08-04 07:07:03

问题


I'm trying to run my django application on heroku.

Folder structure:

app/
  Procfile
  docs/
  ...
  project/
    manage.py
    wsgi.py
    <django apps>

Procfile

web: gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-

Error I'm getting:

2015-02-16T16:05:00.646316+00:00 heroku[web.1]: Starting process with command `gunicorn --pythonpath="$PWD/project" wsgi:application --log-file=-`
2015-02-16T16:05:02.697633+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Listening at: http://0.0.0.0:44846 (3)
2015-02-16T16:05:02.709567+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [9] [INFO] Booting worker with pid: 9
2015-02-16T16:05:02.696968+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Starting gunicorn 19.1.1
2015-02-16T16:05:02.697790+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [3] [INFO] Using worker: sync
2015-02-16T16:05:02.793753+00:00 app[web.1]: [2015-02-16 16:05:02 +0000] [10] [INFO] Booting worker with pid: 10
2015-02-16T16:05:03.157305+00:00 app[web.1]: Traceback (most recent call last):
2015-02-16T16:05:03.157311+00:00 app[web.1]:   File "/app/.heroku/python/bin/gunicorn", line 11, in <module>
2015-02-16T16:05:03.157351+00:00 app[web.1]:     sys.exit(run())
2015-02-16T16:05:03.157383+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
2015-02-16T16:05:03.157461+00:00 app[web.1]:     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
2015-02-16T16:05:03.157463+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
2015-02-16T16:05:03.157506+00:00 app[web.1]:     super(Application, self).run()
2015-02-16T16:05:03.157527+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
2015-02-16T16:05:03.157604+00:00 app[web.1]:     Arbiter(self).run()
2015-02-16T16:05:03.157607+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 196, in run
2015-02-16T16:05:03.157635+00:00 app[web.1]:     self.halt(reason=inst.reason, exit_status=inst.exit_status)
2015-02-16T16:05:03.157656+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 292, in halt
2015-02-16T16:05:03.157730+00:00 app[web.1]:     self.stop()
2015-02-16T16:05:03.157744+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 343, in stop
2015-02-16T16:05:03.157814+00:00 app[web.1]:     time.sleep(0.1)
2015-02-16T16:05:03.157836+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
2015-02-16T16:05:03.157887+00:00 app[web.1]:     self.reap_workers()
2015-02-16T16:05:03.157908+00:00 app[web.1]:   File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers
2015-02-16T16:05:03.158009+00:00 app[web.1]:     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2015-02-16T16:05:03.158075+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
2015-02-16T16:05:03.904714+00:00 heroku[web.1]: Process exited with status 1
2015-02-16T16:05:03.914410+00:00 heroku[web.1]: State changed from starting to crashed

Update 1 My wsgi.py file

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config")
os.environ.setdefault("DJANGO_CONFIGURATION", "Production")

from configurations.wsgi import get_wsgi_application
application = get_wsgi_application()

Here I am just adding some text because SO has this silly minimum amount of text that must be written in a question. I mean, I do get it that quality needs to be kept, but if the problem is self explanatory why force people to write unneeded text? Thanks and have a great day!


回答1:


Adding --preload to the gunicorn command in the Procfile will make your Traceback a lot more readable and show you the actual errors.

Exmaple:

gunicorn project.wsgi:application --preload --workers 1



回答2:


I had a similar problem, after reading he docs for gunicorn, I was able to add

--log-level debug

to the

web: gunicorn project.wsgi:application --log-file -

such that its

web: gunicorn project.wsgi:application --log-file - --log-level debug

In my case the path was also an issue.




回答3:


Finally found the solution, it was a missing dependency of django-organizations. I find it crazy that there is no way (at least not that I could find) to see any useful error output from heroku. I finally did

heroku run bash --app <app_name>

and then ran the wsgi.py file line by line, finally getting some meaningful error on

from configurations.wsgi import get_wsgi_application  # noqa

It was then clear that it's a missing module error, installed it and everything runs perfectly fine.




回答4:


Change your Procfile to:

web: gunicorn project.wsgi:application --log-file=-

You're missing the project module in the python path to the wsgi.py file.



来源:https://stackoverflow.com/questions/28545608/problems-configuring-deployment-with-heroku-gunicorn-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!