I have a django project set up, with gunicorn. I have the following gunicorn_start:
#! /bin/bash
NAME="ostabs2"
DJANGODIR=/srv/osmium/ostabs2
SOCKFILE=/srv/osmium/run/gunicorn.sock
USER=tabuser
GROUP=webapps
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=ostabs2.settings
DANGO_WSGI_MODULE=ostabs2.wsgi
echo "Starting $NAME as 'whoami'"
cd $DJANGODIR
source /srv/osmium/venv/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--preload \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--log-level=debug \
--bind=unix:$SOCKFILE \
--log-file=ostabsgun.log
Running
gunicorn ostabs2.wsgi:application
on the command line works fine, but the gunicorn_start script gives:
Traceback (most recent call last):
File "/srv/osmium/venv/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
super(Application, self).run()
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
Arbiter(self).run()
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 57, in __init__
self.setup(app)
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 113, in setup
self.app.wsgi()
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 66, in wsgi
self.callable = self.load()
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/srv/osmium/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 356, in import_app
__import__(module)
ValueError: Empty module name
What would cause this error? Is there an error in the project, or a missing dependency? I have checked user permissions on all files and directories and tabuser has full read/write access. How can I track down the cause of this problem?
UPDATE: I have followed the advice from this question, the database definitions are correct (I can run syyncdb both locally and on the server). There are no empty strings in the installed apps section, and I have removed references throughout the app to libraries which are no longer used.
Is there anything else which can cause this error?
Related
I am getting this error when trying to configure Supervisor for a Django application on a VPS. So when I look at the error log it seems like it can't find the directory but I don't know what I am doing wrong here.
The path is:
/home/webconexus/portfolio
(portfolio) webconexus#wagtail-portfolio:~/portfolio$ sudo supervisorctl status
portfolio FATAL Exited too quickly (process log may have details
This is my gunicorn_start file:
#!/bin/bash
NAME="portfolio"
DIR=/home/webconexus/portfolio
USER=webconexus
GROUP=webconexus
WORKERS=3
BIND=unix:/home/webconexus/portfolio/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=portfolio.settings
DJANGO_WSGI_MODULE=portfolio.wsgi
LOG_LEVEL=error
cd $DIR
source ../bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH
exec ../bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
--log-file=-
This is my conf file:
[program:portfolio]
command=/home/webconexus/portfolio/bin/gunicorn_start
directory=/home/webconexus/portfolio
user=webconexus
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/webconexus/portfolio/logs/gunicorn-error.log
The new error log:
[2019-02-07 12:58:20 +0000] [3835] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/home/webconexus/portfolio/lib/python3.5/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/home/webconexus/portfolio/lib/python3.5/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/home/webconexus/portfolio/lib/python3.5/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/home/webconexus/portfolio/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/home/webconexus/portfolio/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/home/webconexus/portfolio/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/home/webconexus/portfolio/lib/python3.5/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
ImportError: No module named 'portfolio'
No need to go back to ..
Try this
#!/bin/bash
NAME="portfolio"
DIR=/home/webconexus/portfolio
USER=webconexus
GROUP=webconexus
WORKERS=3
BIND=unix:/home/webconexus/portfolio/run/gunicorn.sock
DJANGO_SETTINGS_MODULE=portfolio.settings
DJANGO_WSGI_MODULE=portfolio.wsgi
LOG_LEVEL=error
cd $DIR
source ./bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DIR:$PYTHONPATH
exec ./bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $WORKERS \
--user=$USER \
--group=$GROUP \
--bind=$BIND \
--log-level=$LOG_LEVEL \
--log-file=-
I'm trying to start a flask application with gunicorn but i'm facing an issue.
When starting it from command line it works fine with this command:
/usr/local/bin/gunicorn --preload --certfile /etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile /etc/letsencrypt/live/server_name.net/privkey.pem -w 17
-b 0.0.0.0:9090 wsgi:app
The same command from a .sh script raise an error :
Traceback (most recent call last):
File "/usr/local/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 61, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 221, in run
super(Application, self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 70, in run
Arbiter(self).run()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 58, in __init__
self.setup(app)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/arbiter.py", line 118, in setup
self.app.wsgi()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/base.py", line 65, in wsgi
self.callable = self.load()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/usr/local/lib/python3.4/dist-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python3.4/dist-packages/gunicorn/util.py", line 372, in import_app
__import__(module)
ImportError: No module named '.0'
Both cli and .sh are run as root.
The same script works fine on a different server so i guess there is a problem with the environment.
I tried to add in the script the following lines at the beginning of the script without success:
$PYTHONPATH=/path/to/my/app
and
$PWD=/path/to/my/app
This is the wsgi file i'm using:
from api import app
if __name__ == "__main__":
app.run()
Any idea what the problem could be?
I was finally able to solve this problem. The following script seems to be working:
cd /path_to_app/
gunicorn --certfile=/etc/letsencrypt/live/server_name.net/fullchain.pem --keyfile=/etc/letsencrypt/live/server_name.net/privkey.pem -w 4 -b 0.0.0.0:9090 wsgi:app
I'm trying to assemble some of the missing pieces in my understanding of how to deploy a Django App to heroku, so that I can launch an instance of Newsdiffs on Heroku.
When I walk through the instructions for running Django on Heroku they have you add a line to Procfile that reads thus: web: gunicorn hellodjango.wsgi --log-file -
But there's no actual file named "hellodjango.wsgi" so ... in that tutorial, where is the "hellodjango.wsgi" module created?
And, perhaps more to the point, why is heroku local balking that I have web.1 | : No module named newsdiffs.wsgi when newdsdiffs/wsgi.py definitely exists.
I can launch the app locally with python website/manage.py runserver but if I do gunicorn newsdiffs.wsgi I get the following, which doesn't include any obvious indications (to my eye) of what I'm doing wrong:
(venv)amanda#mona:newsdiffs$ gunicorn newsdiffs.wsgi
Traceback (most recent call last):
File "/home/amanda/Public/newsdiffs/venv/bin/gunicorn", line 11, in <module>
sys.exit(run())
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 185, in run
super(Application, self).run()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 71, in run
Arbiter(self).run()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 169, in run
self.manage_workers()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 477, in manage_workers
self.spawn_workers()
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 542, in spawn_workers
time.sleep(0.1 * random.random())
File "/home/amanda/Public/newsdiffs/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 209, in handle_chld
self.reap_workers()
File "/home/amanda/Public/newsdiffs/venv/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>
The gunicorn command takes the name of a Python module, not a path to a file. If hellodjango.wsgi is the name of the Python module, the corresponding file will be hellodjango/wsgi.py or hellodjango/wsgi/__init__.py.
This is the same syntax used to refer to a module when importing it, e.g. you would import * from hellodjango.wsgi to get access to the things defined in hellodjango/wsgi.py.
The django-admin startproject command will create a wsgi.py file in the same directory as the project's settings.py and urls.py files.
Here's the error:
Traceback (most recent call last):
File "/var/apps/tango/envs/tango-env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
self.load_middleware()
File "/var/apps/tango/envs/tango-env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 45, in load_middleware
mw_class = import_by_path(middleware_path)
File "/var/apps/tango/envs/tango-env/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 21, in import_by_path
module = import_module(module_path)
File "/var/apps/tango/envs/tango-env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/var/apps/tango/envs/tango-env/local/lib/python2.7/site-packages/django/middleware/doc.py", line 4, in <module>
warnings.warn(__doc__, PendingDeprecationWarning, stacklevel=2)
TypeError: expected string or buffer
TypeError: expected string or buffer
Tango is the user I created specifically for this project.
I'm using upstart so in /etc/init/tango-wsgi.conf looks like:
exec /var/apps/tango/envs/tango-env/bin/uwsgi \
--uid tango \
--home /var/apps/tango/envs/tango-env \
--pythonpath /var/apps/tango/tango/src \
--wsgi-file /var/apps/tango/tango/src/tango_cms/wsgi.py \
--socket /tmp/tango-uwsgi.sock \
--chmod-socket \
--logdate \
--optimize 2 \
--processes 2 \
--master \
--logto /var/apps/tango/logs/uwsgi.log
UPDATE:
My nginx.conf has following entry:
location / {
uwsgi_pass unix:/tmp/tango-uwsgi.sock;
include /etc/nginx/uwsgi_params;
}
Please help.
Same problem here. I fixed it deleting the following line on tango-wsgi.conf file:
--optimize 2 \
Optimize allows some kind of python optimization: More info
Not sure why it's an error, you could try removing "XViewMiddleware" if it's installed.
$ 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!