This is my uwsgi ini file,
[uwsgi]
chdir=/root/projects/cbapis/cbapis
module=cbAPIs.wsgi:application
env = DJANGO_SETTINGS_MODULE=cbAPIs.settings.production
http=0.0.0.0:8002
workers=1
home=/root/projects/cbapis/cbapis/env
This is the django wsgi file,
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cbAPIs.settings.production")
application = get_wsgi_application()
When I run server with uwsgi, it runs fine,
uwsgi --ini cbapi_uwsgi_config.ini
Below is my supervisor conf for this project,
[program:djangocbapis]
command=uwsgi --ini /root/cbapi_uwsgi_config.ini
environment =
DJ_DEV_SERVER_DB_NAME="****",
DJ_DEV_SERVER_DB_USER="****",
DJ_DEV_SERVER_DB_HOST="*****",
DJ_DEV_SERVER_DB_PASSWORD="*****",
autostart=true
autorestart=true
user=root
priority=400
stderr_logfile=/var/app/cbapis/log/cbapis.log
When I run this uwsgi server via supervisor, it does not run. I get the following error in the log file,
--- no python application found, check your startup logs for errors ---
I have similar supervisor and uwsgi configuration for my other django projects in the same server, which are running fine with supervisor and uwsgi.
But I can't figure out why it cannot find python application while running with supervisor.
So, please help me in this matter.
Try to give full path to uwsgi like /usr/bin/uwsgi or /usr/local/bin/uwsgi. If you are on ubuntu/linux then type command which uwsgi to get full path. It will work.
[program:djangocbapis]
command=/usr/bin/uwsgi --ini /root/cbapi_uwsgi_config.ini
autostart=true
autorestart=true
user=root
priority=400
stderr_logfile=/var/app/cbapis/log/cbapis.log
setup the environment variable in uwsgi .ini file.
env = DJ_DEV_SERVER_DB_NAME="****",
env = DJ_DEV_SERVER_DB_USER="****",
env = DJ_DEV_SERVER_DB_HOST="*****",
env = DJ_DEV_SERVER_DB_PASSWORD="*****",
Related
I cannot seem to get celery working in production using supervisor. I am normally using it in local development running the command. However, when I make a supervisor setup, it is not working. Reading the logs I am getting the error:
Unable to load celery application.
The module inp_proj was not found.
My .conf file for supervisor is:
[program:inp_proj]
directory=/www/[project_directory]/inp_proj
command=/www/[project_directory]/venv/bin/celery -A inp_proj worker --loglevel=INFO
user=jan
numprocs=1
stdout_logfile=/var/log/celery/inp_proj.log
stderr_logfile=/var/log/celery/inp_proj.log
autostart=true
autorestart=true
startsecs=10
stopwaitsecs = 600
killasgroup=true
priority=998
this is my celery.py file:
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'inp_proj.settings')
app = Celery('inp_proj')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
It is located inside project directory and inside inp_proj.
I tried changing the celery command in the created config file, adding environment path to supervisor config file but nothing seems to be working. If I manually active the venv with
source venv/bin/activate
and then start the worker manually, it works normally. But when using supervisor, it doesn't work.
When I deploy my Django app on Heroku I got following error
Error: No application module specified.
I cleary see that Heroku see wsgi file
Starting process with command `gunicorn --pythonpath application.george_paintings.george_paintings.wsgi --log-file - --log-level debug`
But then I got this error. My Procfile looks like this
web: gunicorn --pythonpath application.george_paintings.george_paintings.wsgi --log-file - --log-level debug
The WSGI
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'george_paintings.settings')
application = get_wsgi_application()
I tried to see logs with
heroku run rails console -a george-paintings
but got an error
bash: rails: command not found
You simply paste cmd
your terminal ( heroku logs --tail ) its shows your error
I saw news on docs.gunicorn.org for gunicorn v.19:
Deprecations
run_gunicorn, gunicorn_django and gunicorn_paster are now completely
deprecated and will be removed in the next release. Use the gunicorn
command instead.
I run my applications from virtual environments, created with virtualenv with this command in supervisor:
[program:my_app]
command=/var/www/.virtualenvs/my_app/bin/gunicorn_django -c /var/www/my_app/conf/gunicorn.conf.py
user=www-data
group=www-data
daemon=false
debug=false
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/www/my_app/log/supervisor.log
How should I change my settings to run my projects with the new version gunicorn?
The command line should be changed to the following
command=/var/www/.virtualenvs/my_app/bin/gunicorn my_app.wsgi:application -c /var/www/my_app/conf/gunicorn.conf.py
This is assuming that you have the file my_app/wsgi.py. Since Django 1.4, startproject has generated a wsgi.py file for you as part of your project. I'd assume you have this, but if not you can use the following snippet to create that file.
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_app.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
See https://docs.djangoproject.com/en/1.6/howto/deployment/wsgi/
You may need to ensure that the my_app directory is in your PYTHONPATH if it is not already, or you will get errors.
To test this out standalone on the command line with a new django project, the following should work assuming you have django and gunicorn already installed in you current environment.
django-admin.py startproject myproject
cd myproject
export PYTHONPATH=$PYTHONPATH:.
gunicorn myproject.wsgi:application -b localhost:8008
I have my project based on the django startproject: https://github.com/lincolnloop/django-startproject/
Here is my procfile:
web: gunicorn <myproject>.wsgi:application
Right now I have my set up like this:
[myproject]
---[conf]
------[local]
---------settings.py
------[qa]
---------settings.py
---[server_configs]
------[local]
---------django.wsgi
------[qa]
---------django.wsgi
My django.wsgi looks like this:
import os
import sys
import django.core.handlers.wsgi
sys.path.append('/app')
sys.path.append('/app/myproject')
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.conf.qa.settings'
application = django.core.handlers.wsgi.WSGIHandler()
I want to use the qa/django.wsgi for Heroku, but I am getting an error saying:
ImportError: No module named [myproject].wsgi
I have already gone through and tried solutions in this post: Configuring gunicorn for Django on Heroku but with no luck on my end.
Right now my PYTHONPATH is /app and have already tried Gunicorn+Django+Heroku. Python Path Issue with no luck either.
I had a similar problem once. Basically, you're running gunicorn from your root directory, but your wsgi is in [my_project]/[server_configs]/[qa]/.
There are two ways to go about it. If each of those directories has an init.py file, you can call it like a normal python module. Use:
web: gunicorn [myproject].[server_configs].[qa].django.wsgi:application
If they don't have init.py files (I didn't), you'll need your Procfile to switch into the proper directory. Try:
web: sh -c 'cd [server_configs]/[qa] && gunicorn django.wsgi:application'
Basically this is running a command in your shell to (1) change directories and (2) run gunicorn.
Heroku allows you to use environment variables in your Procfile. If you define an environment variable on Heroku, like so: heroku config:set WSGI_PATH=path/to/my/file/wsgi.py, then in your Procfile do: gunicorn $WSGI_PATH:application you should be good to go!
I am trying to deploy the simplest possible "hello world" celery configuration on heroku for my Django app. My Procfile is as follows:
web: gunicorn myapp.wsgi
worker: celery -A myapp worker -l info -B -b amqp://XXXXX:XXXXX#red-thistle-3.bigwig.lshift.net:PPPP/XXXXX
This is the RABBITMQ_BIGWIG_RX_URL that I'm giving to the celery worker. I have the corresponding RABBITMQ_BIGWIG_TX_URL in my settings file as the BROKER_URL.
If I use these broker URLs in my local dev environment, everything works fine and I can actually use the Heroku RabbitMQ system. However, when I deploy my app to Heroku it isn't working.
This Procfile seems to work (although Celery is giving me memory leak issues).
web: gunicorn my_app.wsgi
celery: celery worker -A my_app -l info --beat -b amqp://XXXXXXXX:XXXXXXXXXXXXXXXXXXXX#red-thistle-3.bigwig.lshift.net:PPPP/XXXXXXXXX