0

How can I run the legacy of django project 1.5 with gunicorn?

$ gunicorn wsgi:application -b 127.0.0.1:8000
[2017-05-18 16:48:00 +0000] [15535] [INFO] Starting gunicorn 19.6.0
[2017-05-18 16:48:00 +0000] [15535] [INFO] Listening at: http://127.0.0.1:8000 (15535)
[2017-05-18 16:48:00 +0000] [15535] [INFO] Using worker: sync
[2017-05-18 16:48:00 +0000] [15539] [INFO] Booting worker with pid: 15539
[2017-05-18 16:48:00 +0000] [15539] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 384, in import_app
    __import__(module)
ImportError: No module named wsgi
[2017-05-18 16:48:00 +0000] [15539] [INFO] Worker exiting (pid: 15539)
[2017-05-18 16:48:00 +0000] [15535] [INFO] Shutting down: Master
[2017-05-18 16:48:00 +0000] [15535] [INFO] Reason: Worker failed to boot.

This is how I run it on dev mode:

$ python manage.py runserver
>>> Starting gulp watch
>>> gulp watch gulp process on pid 15935
Validating models...

0 errors found
May 18, 2017 - 16:53:39
Django version 1.5.12, using settings 'website.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[16:53:39] Warning: gulp version mismatch:
[16:53:39] Global gulp is 3.9.1
[16:53:39] Local gulp is 3.5.6
[16:53:39] Using gulpfile /var/www/html/legacy-project/gulpfile.js
[16:53:39] Starting 'sass'...
[16:53:40] Finished 'sass' after 118 ms
[16:53:40] Starting 'watch'...
[16:53:40] Finished 'watch' after 223 ms
[16:53:40] Live reload server listening on: 35729

And it works ok. But I am told that I should not run it like that in production server. I should use gunicorn.

I am new to Django project and I am taking this project from the previous developers. They have left me with no proper instructions for migrating it to a new server.

Any ideas how I can run it properly with gunicorn?

EDIT:

$ gunicorn my-django.wsgi
[2017-05-18 17:40:16 +0000] [19389] [INFO] Starting gunicorn 19.6.0
[2017-05-18 17:40:16 +0000] [19389] [INFO] Listening at: http://127.0.0.1:8000 (19389)
[2017-05-18 17:40:16 +0000] [19389] [INFO] Using worker: sync
[2017-05-18 17:40:16 +0000] [19393] [INFO] Booting worker with pid: 19393
[2017-05-18 17:40:16 +0000] [19393] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 384, in import_app
    __import__(module)
ImportError: No module named my-django.wsgi
[2017-05-18 17:40:16 +0000] [19393] [INFO] Worker exiting (pid: 19393)
[2017-05-18 17:40:16 +0000] [19389] [INFO] Shutting down: Master
[2017-05-18 17:40:16 +0000] [19389] [INFO] Reason: Worker failed to boot.
Run
  • 54,938
  • 169
  • 450
  • 748
  • 1
    Try running `gunicorn website.wsgi` or `gunicorn website.wsgi:application`, where `website` is the name of the Django project. You should run this from the same directory that contains `manage.py`. Note that Django 1.5 is out of date and insecure. – Alasdair May 18 '17 at 16:09
  • @Alasdair i have tried that but still no luck. please see my edit above. thanks. – Run May 18 '17 at 16:53
  • 1
    Maybe this question will help http://stackoverflow.com/questions/39460892/gunicorn-no-module-named-myproject – kichik May 18 '17 at 16:58
  • 1
    If you add your project layout and wsgi.py it might show what the problem is. Using `my-django` instead of the real name makes it harder to solve the problem. – Alasdair May 18 '17 at 20:25
  • @Alasdair i would love to. but this legacy is just too messy! it is going to take forever to show you guys the project layout. – Run May 18 '17 at 20:30
  • 1
    I don't have any other suggestions. Hope you get it to work. – Alasdair May 18 '17 at 20:34
  • @Alasdair i will try work something out later. thanks for wanting to help! – Run May 18 '17 at 20:38

0 Answers0