nginx with gunicorn and django on centos 7 - django

I'm trying to make my nginx and gunicorn start working... but seemingly trying everything I could do, fails...
If I do:
systemctl restart nginx
systemctl status nginx
It shows green, and it works...
If I do:
systemctl start gunicorn.socket
systemctl status gunicorn.socket -l
It shows green and works fine...
But if I do:
systemctl start gunicorn.service
systemctl status gunicorn.service -l
it shows me the following message:
gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Thu 2020-09-10 14:17:23 UTC; 15min ago
Process: 22145 ExecStart=/home/scorg/pro/sc_project/bin/gunicorn --workers 3 --bind unix:/home/scorg/pro/projects/sc/sc.sock sc.wsgi:application (code=exited, status=3)
Main PID: 22145 (code=exited, status=3)
Sep 10 14:17:23 gunicorn[22145]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
Sep 10 14:17:23 gunicorn[22145]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Sep 10 14:17:23 gunicorn[22145]: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Sep 10 14:17:23 : ModuleNotFoundError: No module named 'sc'
Sep 10 14:17:23 : [2020-09-10 14:17:23 +0000] [22152] [INFO] Worker exiting (pid: 22152)
Sep 10 14:17:23 : [2020-09-10 14:17:23 +0000] [22145] [INFO] Shutting down: Master
Sep 10 14:17:23 : [2020-09-10 14:17:23 +0000] [22145] [INFO] Reason: Worker failed to boot.
Sep 10 14:17:23 : gunicorn.service: main process exited, code=exited, status=3/NOTIMPLEMENTED
Sep 10 14:17:23 : Unit gunicorn.service entered failed state.
Sep 10 14:17:23 : gunicorn.service failed.
I kind of understand it is bind problem and I followed this question:
Gunicorn, no module named 'myproject
But whatever module I try to bind with the following command, it just doesn't work:
gunicorn --bind 0.0.0.0:8000 wsgi:application
I tried wsgi, sc.wsgi, sc/wsgi, /whole_path/wsgi It's just always the same result... mofule not found...
my gunicorn.service looks like this:
#!/bin/sh
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=root
#scorg
Group=root
#www-data
Environment=SECRET_KEY=secret
WorkingDirectory=/home/scorg/pro/projects/sc/sc
ExecStart=/home/scorg/pro/sc_project/bin/gunicorn --workers 3 --bind unix:/home/scorg/pro/projects/sc/sc.sock sc.wsgi:application
[Install]
WantedBy=multi-user.target
The structure is as following:
sc
├── manage.py
├── sc
│ ├── asgi.py
│ ├── __init__.py
│ ├── __pycache__
│ ├── settings.py
│ ├── urls.py
│ └── wsgi.py
└── sc_site
├── admin.py
├── apps.py
├── forms.py
├── models.py
├── __pycache__
├── static
│ ├── admin
│ ├── css
│
├── templates
├── urls.py
└── views.py
I'm in the world of pain at the time. I was struggling with Apache ... I'm noob at centos 7/ linux servers management... Apparently I am stuck... If I forgot to give some extra information... Please let me know, I will happily make an update...
Also I did make sure that I set up gunicorn... So it is on the system and works...:
yum install python-gunicorn
Update
After all fight with the options for gunicorn, it is using python 2.7. I have python 3.8.5... I tried to follow this tutorial How to get Gunicorn to use Python 3 instead of Python 2 (502 Bad Gateway) , but so far I cannot figure out completely what to do... I did everything and it's still using python2.7... Interesting thing:
I tried to delete gunicorn... pip uninstall guncorn
And system tells me that I don't have gunicorn, same story with pip3...
I installed gunicorn with pip3 install gunicorn, but it still trying to use python2.7:
[[/home/scorg/pro]]# sc_project/bin/gunicorn_start
Starting scorg_app as root
DJANGO_SETTINGS_MODULE
PYTHONPATH
2020-09-14 11:15:43 [4865] [INFO] Starting gunicorn 18.0
2020-09-14 11:15:43 [4865] [DEBUG] Arbiter booted
2020-09-14 11:15:43 [4865] [INFO] Listening at: unix:/home/scorg/pro/run/gunicorn.sock (4865)
2020-09-14 11:15:43 [4865] [INFO] Using worker: sync
2020-09-14 11:15:43 [4871] [INFO] Booting worker with pid: 4871
2020-09-14 11:15:43 [4871] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.scrap.scrap.wsgi
2020-09-14 11:15:43 [4871] [INFO] Worker exiting (pid: 4871)
2020-09-14 11:15:43 [4872] [INFO] Booting worker with pid: 4872
2020-09-14 11:15:43 [4872] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
2020-09-14 11:15:43 [4872] [INFO] Worker exiting (pid: 4872)
2020-09-14 11:15:43 [4873] [INFO] Booting worker with pid: 4873
2020-09-14 11:15:43 [4873] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.scrap.scrap.wsgi
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495,in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/site-packages/gunicorn/workers/base.py", line106, in init_process
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/site-packages/gunicorn/util.py", line 354, inimport_app
__import__(module)
ImportError: No module named projects.sc.sc.wsgi
2020-09-14 11:15:43 [4873] [INFO] Worker exiting (pid: 4873)
Traceback (most recent call last):
File "/bin/gunicorn", line 9, in <module>
load_entry_point('gunicorn==18.0', 'console_scripts', 'gunicorn')()
File "/usr/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 71, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/lib/python2.7/site-packages/gunicorn/app/base.py", line 143, in run
Arbiter(self).run()
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 203,in run
self.halt(reason=inst.reason, exit_status=inst.exit_status)
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 298,in halt
self.stop()
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 341,in stop
self.reap_workers()
File "/usr/lib/python2.7/site-packages/gunicorn/arbiter.py", line 452,in reap_workers
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
But when I try uninstall gunicorn, it tried to uninstall gunicorn for python3.8... While I'm trying to run gunicorn it runs for python2.7... Unbelievable...
[ [/home/scorg/pro]]# pip uninstall gunicorn
Found existing installation: gunicorn 20.0.4
Uninstalling gunicorn-20.0.4:
Would remove:
/usr/local/bin/gunicorn
/usr/local/lib/python3.8/site-packages/gunicorn-20.0.4.dist-info/*
/usr/local/lib/python3.8/site-packages/gunicorn/*
Proceed (y/n)? y
Successfully uninstalled gunicorn-20.0.4

If you have virtualenv follow this steps:
create guncorn.conf config file
ex: touch /opt/yourproject/gunicorn.conf
import multiprocessing
workers = multiprocessing.cpu_count()*2+1
bind='unix:/var/run/gunicorn.sock'
logfile="/var/log/guni.log"
errorlog = '-'
loglevel = 'info'
accesslog = '-'
timeout=120
proc_name = "yourproject"
user="root"
group="root"
create "gunicorn_start" file.
ex: touch /opt/yourproject/gunicorn_start
#!/bin/bash
NAME="yourproject"
DJANGODIR= **** #ex: /home/yourproject/ #change this
ENVBIN=/yourvirtualenvdir/bin/
SOCKFILE=/var/run/gunicorn.sock
USER=root
GROUP=root
NUM_WORKERS=5 #change this
DJANGO_SETTINGS_MODULE= **** #ex: yourproject.settigns.main #change this
DJANGO_WSGI_MODULE=****.wsgi #ex: yourproject.wsgi #change this
TIMEOUT=120
echo "Starting $NAME as `whoami`"
## Activate the virtual environment
cd $DJANGODIR
source $ENVBIN/activate
cd $DJANGODIR
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
## Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
## Start your Django Unicorn
## Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec $ENVBIN/gunicorn ${DJANGO_WSGI_MODULE}:application -c=/opt/yourproject/gunicorn.conf
create service
[Unit]
Description=My Python Service
[Service]
User=root
Restart=always
Type=simple
WorkingDirectory=/opt/yourproject/
ExecStart=/usr/bin/sh gunicorn_start
[Install] WantedBy=multi-user.target

Have you tried to add "--chdir " in ExecStart?
like
ExecStart=/home/scorg/pro/sc_project/bin/gunicorn --chdir /home/scorg/pro/projects/sc/sc --workers 3 --bind unix:/home/scorg/pro/projects/sc/sc.sock sc.wsgi:application

Related

Python + Django debug startup on WSGI

I'm facing a crash launching with GUNICORN my App on MacOsX Sierra.
Is there any way to better understand the error message? Like to know which dependency is missing or something like that?
I searched online for more log-level info but, right now, the error is not easy to understand.
I report the error if somebody has any clue or any tool to drill down the exception and find it out!
I believe you did
I Already tried this solution and django-haystack was already there
pip install haystack
pip uninstall haysatck
pip install django-haystack
Thanks in advance
gunicorn direttoo.wsgi:application --workers 1 --bind 127.0.0.1:8001 --log-level Info
[2017-03-24 12:30:51 +0100] [3304] [INFO] Starting gunicorn 19.6.0
[2017-03-24 12:30:51 +0100] [3304] [INFO] Listening at: http://127.0.0.1:8001 (3304)
[2017-03-24 12:30:51 +0100] [3304] [INFO] Using worker: sync
[2017-03-24 12:30:51 +0100] [3307] [INFO] Booting worker with pid: 3307
[2017-03-24 11:30:51 +0000] [3307] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
File "/Users/diegobanovaz/Projects/direttoo/direttoo/wsgi.py", line 36, in <module>
application = get_wsgi_application()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup()
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/diegobanovaz/Projects/direttoo/env/lib/python2.7/site-packages/haystack/__init__.py", line 56, in <module>
maxnofile[1]))
ValueError: current limit exceeds maximum limit
[2017-03-24 11:30:51 +0000] [3307] [INFO] Worker exiting (pid: 3307)
[2017-03-24 12:30:51 +0100] [3304] [INFO] Shutting down: Master
[2017-03-24 12:30:51 +0100] [3304] [INFO] Reason: Worker failed to boot.

Problems configuring deployment with Heroku/gunicorn/django

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!
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
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.
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.
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.
I solved it. I followed these steps:
Remove all the unused libraries.
Delete requirements.txt file.
Create a new requirements.txt file.
Commit to Git and then deploy on Heroku.

Heroku NameError: name 'application' is not defined

I'm trying to deploy a django app to heroku and it keeps crashing. Does anyone have any idea what I'm doing wrong?
Here is my Procfile:
web: python app/manage.py collectstatic --noinput; gunicorn --workers=4 --bind=0.0.0.0:$PORT app.settings
And here is a snippet from my heroku logs:
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/arbiter.py", line 456, in spawn_worker
self.wsgi = self.app.wsgi()
app = eval(obj, mod.__dict__)
File "<string>", line 1, in <module>
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/base.py", line 101, in wsgi
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 24, in load
self.callable = self.load()
return util.import_app(self.app_uri)
NameError: name 'application' is not defined
2014-07-04 17:58:23 [4] [INFO] Starting gunicorn 0.13.4
2014-07-04 17:58:23 [10] [ERROR] Exception in worker process:
worker.init_process()
File "/app/.heroku/python/lib/python2.7/site-packages/gunicorn/util.py", line 250, in import_app
2014-07-04 17:58:23 [9] [INFO] Booting worker with pid: 9
2014-07-04 17:58:23 [10] [INFO] Worker exiting (pid: 10)
2014-07-04 17:58:23 [4] [INFO] Listening at: http://0.0.0.0:36148 (4)
2014-07-04 17:58:23 [7] [INFO] Booting worker with pid: 7
It says application not found. well try changing gunicorn
web: gunicorn YourProject.wsgi
I solved my own issue after doing several things, including upgrading my django install and changing my procfile to this:
web: gunicorn app.wsgi --pythonpath app --log-file -

gunicorn_django -b 0.0.0.0 project_name/settings/production.py

$ python manage.py run_gunicorn 0.0.0.0:80 --settings=project_name.settings.production
<- It's run, OK.
but,
$ gunicorn_django -b 0.0.0.0:80 project_name/settings/production.py
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 106, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/djangoapp.py", line 102, in load
return mod.make_wsgi_application()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/django_wsgi.py", line 36, in make_wsgi_application
if get_validation_errors(s):
File "/usr/local/lib/python2.7/dist-packages/django/core/management/validation.py", line 35, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 166, in get_app_errors
self._populate()
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 72, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/loading.py", line 94, in load_app
app_module = import_module(app_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
> ImportError: No module named accounts
2013-06-29 01:56:53 [30859] [INFO] Worker exiting (pid: 30859)
2013-06-29 01:56:53 [30854] [INFO] Shutting down: Master
2013-06-29 01:56:53 [30854] [INFO] Reason: Worker failed to boot.
How can I solve this problem?
I want to run on daemon.
Thanks.
This looks like an issue related to your PYTHONPATH. Try adding the path that contains the accounts module to your python path, using gunicorn's --pythonpath.
If you have newer gunicorn/Django versions using gunicorn via management command should be the preffered way - and it should be more safe regarding issues like this.
Try running your django app using gunicorn instead of django_gunicorn:
$ gunicorn mydjangoproject.wsgi:application
There is also an alternative solution to fix the gunicorn_django script, see here. I ran into the issue when upgrading from gunicorn 18.0 to 19.1.1. Cheers!

Correct way of creating supervisord script for gunicorn? Django 1.6

Here is my gonicorn.conf, but I can't seem to get the command right. The command Im trying is working when I type it in the command line, but not as an Supervisor command.
[program:gunicorn]
directory = /home/USER/.virtualenvs/SITE/myApp/
command=/home/USER/.virtualenvs/SITE/bin/python /home/USER/.virtualenvs/SITE/myApp/manage.py run_gunicorn myApp.wsgi:application -c /home/USER/.virtualenvs/SITE/myApp/gunicorn.conf.py
user = USER
autostart = true
autorestart = true
redirect_stderr = true
stdout_logfile = /home/USER/logs/gunicorn.log
stderr_logfile = /home/USER/logs/gunicorn_err.log
What is the correct command for gunicorn?
Here is the error Im getting when I try to start gunicorn:
/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/sorl/thumbnail/helpers.py:5: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
from django.utils import simplejson
2013-02-25 13:46:55 [3975] [INFO] Starting gunicorn 0.17.2
2013-02-25 13:46:55 [3975] [INFO] Listening at: http://127.0.0.1:8000 (3975)
2013-02-25 13:46:55 [3975] [INFO] Using worker: sync
2013-02-25 13:46:55 [3988] [INFO] Booting worker with pid: 3988
2013-02-25 13:46:55 [3988] [ERROR] Exception in worker process:
Traceback (most recent call last):
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
worker.init_process()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
self.callable = self.load()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 133, in load
return mod.make_command_wsgi_application(self.admin_media_path)
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
reload_django_settings()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 109, in reload_django_settings
logging_config_func(settings.LOGGING)
File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python2.7/logging/config.py", line 503, in configure
raise ValueError("dictionary doesn't specify a version")
ValueError: dictionary doesn't specify a version
Traceback (most recent call last):
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 485, in spawn_worker
worker.init_process()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 100, in init_process
self.wsgi = self.app.wsgi()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 103, in wsgi
self.callable = self.load()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/djangoapp.py", line 133, in load
return mod.make_command_wsgi_application(self.admin_media_path)
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 113, in make_command_wsgi_application
reload_django_settings()
File "/home/USERNAME/.virtualenvs/SITE/local/lib/python2.7/site-packages/gunicorn/app/django_wsgi.py", line 109, in reload_django_settings
logging_config_func(settings.LOGGING)
File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python2.7/logging/config.py", line 503, in configure
raise ValueError("dictionary doesn't specify a version")
ValueError: dictionary doesn't specify a version
That specific error can be fixed by adding this variable to your settings file. I ran into this when upgrading a django project from Django 1.3 to Django 1.5.
(See https://docs.djangoproject.com/en/dev/topics/logging/ for more info)
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
}
[program:projectname_gunicorn_live]
command=/home/myusername/projectname-live/bin/django run_gunicorn -b 127.0.0.1:1559
directory=/home/myusername/projectname-live/
user=myusername
autostart=True
autorestart=True
redirect_stderr=True
Link: https://gist.github.com/oaksakal/1143612
Another Link: Gunicorn Supervisor Startup Error