使用Heroku / gunicorn / django配置部署时出现问题

时间:2015-02-16 16:08:51

标签: django heroku deployment wsgi django-wsgi

我试图在heroku上运行我的django应用程序。

文件夹结构:

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

Procfile

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

错误我得到了:

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

更新1 我的wsgi.py文件

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()

这里我只是添加了一些文本,因为SO有一个必须写在问题中的最少量的文本。我的意思是,我确实认为需要保持质量,但如果问题是自我解释的,为什么要强迫人们编写不需要的文字?谢谢,祝你有个美好的一天!

4 个答案:

答案 0 :(得分:2)

--preload添加到Procfile中的gunicorn命令将使您的Traceback更具可读性,并向您显示实际错误。

〔实施例:

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

答案 1 :(得分:2)

我有一个类似的问题,在阅读了他docs的gunicorn后,我能够添加

--log-level debug

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

这样它的

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

在我的情况下,路径也是一个问题。

答案 2 :(得分:1)

终于找到了解决方案,这是django-organizations的缺失依赖。我觉得很疯狂,没有办法(至少不是我能找到的)看到来自heroku的任何有用的错误输出。我终于做到了

heroku run bash --app <app_name>

然后逐行运行wsgi.py文件,最后在

上得到一些有意义的错误
from configurations.wsgi import get_wsgi_application  # noqa

很明显,这是一个缺少的模块错误,安装它,一切都运行得很好。

答案 3 :(得分:0)

将您的Procfile更改为:

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

你错过了wsgi.py文件的python路径中的project模块。