gunicorn.errors.HaltServer:<HaltServer'Worker无法启动。 3> django
我有一个Django的应用程序,并试图设置它与gunicorn第一,后来与主pipe和nginx。
该应用程序正常运行与正常的Django命令完全像python manage.py runserver
我安装gunicorn使用pip像pip install gunicorn
和django版本是1.5.3
当我在下面的虚拟env中运行下面的命令
gunicorn hello.wsgi:application -b xx.xxx.xxx.xx:8000
并面临错误
Traceback (most recent call last): File "/root/Envs/proj/bin/gunicorn", line 9, in <module> load_entry_point('gunicorn==19.0.0', 'console_scripts', 'gunicorn')() File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run() File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 166, in run super(Application, self).run() File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run Arbiter(self).run() File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run self.manage_workers() File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers self.spawn_workers() File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers time.sleep(0.1 * random.random()) File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld self.reap_workers() File "/root/Envs/proj/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 459, in reap_workers raise HaltServer(reason, self.WORKER_BOOT_ERROR) gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
那么,为什么实际上遇到了上述错误,最新的解决scheme呢?
其实这里的问题是wsgi文件本身,之前在django 1.3之前的wsgi文件被命名为.wsgi
的扩展名,但是现在在最近的版本中将会创build并扩展.py
,即wsgi文件必须是python模块
所以文件应该是hello_wsgi.py
,命令应该是
gunicorn hello:application -b xx.xxx.xxx.xx:8000
你没有显示完整的输出。 这可能看起来像
$ gunicorn elcarweb.wsgi [2015-10-27 21:01:47 +0000] [5429] [INFO] Starting gunicorn 19.2.1 [2015-10-27 21:01:47 +0000] [5429] [INFO] Listening at: http://127.0.0.1:8000 (5429) [2015-10-27 21:01:47 +0000] [5429] [INFO] Using worker: sync [2015-10-27 21:01:47 +0000] [5434] [INFO] Booting worker with pid: 5434 [2015-10-27 21:01:47 +0000] [5434] [ERROR] Exception in worker process: Traceback (most recent call last): File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker worker.init_process() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process self.wsgi = self.app.wsgi() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load return self.load_wsgiapp() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp return util.import_app(self.app_uri) File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app __import__(module) ImportError: No module named elcarweb.wsgi Traceback (most recent call last): File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 503, in spawn_worker worker.init_process() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 116, in init_process self.wsgi = self.app.wsgi() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load return self.load_wsgiapp() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp return util.import_app(self.app_uri) File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app __import__(module) ImportError: No module named elcarweb.wsgi [2015-10-27 21:01:47 +0000] [5434] [INFO] Worker exiting (pid: 5434) Traceback (most recent call last): File "/home/tomek/Elcar/elcarweb/env/bin/gunicorn", line 11, in <module> sys.exit(run()) File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 189, in run super(Application, self).run() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run Arbiter(self).run() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 170, in run self.manage_workers() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 473, in manage_workers self.spawn_workers() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 537, in spawn_workers time.sleep(0.1 * random.random()) File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 210, in handle_chld self.reap_workers() File "/home/tomek/Elcar/elcarweb/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 455, in reap_workers raise HaltServer(reason, self.WORKER_BOOT_ERROR) gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
最后一次引用几乎相同,但在您看到所需的信息之前:
ImportError: No module named elcarweb.wsgi
如果你看到这个错误,那么解决方法是用--chdir=/your/app/dir
参数运行gunicorn。
我得到了同样的错误。 Gunicorn以root身份执行时正在工作,但以非特权用户身份执行时以此方式失败。 在我的情况下,我安装了'数据集'python模块'pip安装数据集',它拧上/usr/lib/python2.7/site-packages/dataset
的权限只能由root帐户读取。 在其他模块安装为依赖像这是正常的。
修正:
chmod -R a+rX /usr/lib/python2.7/site-packages/dataset* chmod -R a+rX /usr/lib/python2.7/site-packages/normality*
还有一个问题是用pip自动安装的yaml包,但是我还没有find什么。 解决的办法是从fedora软件包重新安装:
dnf -y install python-yaml
我也有类似的错误在Ubuntu 16.04,Django 1.11,使用systemd。
我的问题是,我已经把我的设置分成单独的文件; 即:而不是在项目/ settings.py中的所有设置,我有几个设置文件像project / settings / dev.py。
我不得不从项目/ wsgi.py文件中更新DJANGO_SETTINGS_MODULE:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
至
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings.dev")
然后gunicorn工作。