I'm trying to use Celery on my Beanstalk environment (this is the final piece in order to complete the technology stack of my project :P).
This is what I've done so far:
Since, RabbitMQ is the best broker for Celery and Amazon does not provide a dedicated service I created a custom AMI based on Ubuntu 13 64bit
installed RabbitMQ
removed the default user guest/guest
created a custom user
created a custom virtual host
installed admin plugins
tested my configuration using the http API in order to confirm that my RabbitMQ server is up and running.
So far so good! Then in my beanstalk .config file I added a couple of commands for celery:
04_celery_periodic_tasks:
command: "celery worker --app=com.cygora --loglevel=info --beat --autoreload -n period_tasks_worker.%h"
leader_only: true
05_celery_standard_worker:
command: "celery worker --app=com.cygora --loglevel=info --autoreload -n worker_1.%h"
Once I deployed my app, I didn't find any error related to celery (so I'm assuming it's all ok, from "the Python/Django side")... but as soon as I use a feature of my site that requires sending a message to Rabbit via Celery I get a timeout exception:
[Thu Feb 20 22:01:24 2014] [error] File "/opt/python/run/venv/lib/python2.7/site-packages/kombu/transport/pyamqp.py", line 111, in establish_connection
[Thu Feb 20 22:01:24 2014] [error] conn = self.Connection(**opts)
[Thu Feb 20 22:01:24 2014] [error] File "/opt/python/run/venv/lib/python2.7/site-packages/amqp/connection.py", line 165, in __init__
[Thu Feb 20 22:01:24 2014] [error] self.transport = create_transport(host, connect_timeout, ssl)
[Thu Feb 20 22:01:24 2014] [error] File "/opt/python/run/venv/lib/python2.7/site-packages/amqp/transport.py", line 274, in create_transport
[Thu Feb 20 22:01:24 2014] [error] return TCPTransport(host, connect_timeout)
[Thu Feb 20 22:01:24 2014] [error] File "/opt/python/run/venv/lib/python2.7/site-packages/amqp/transport.py", line 89, in __init__
[Thu Feb 20 22:01:24 2014] [error] raise socket.error(last_err)
[Thu Feb 20 22:01:24 2014] [error] error: timed out
I specified the broker url in settings as:
BROKER_URL = "amqp://myuser:mypassword#myelasticip:5672/myvirtualhost"
What I'm missing or what I did wrong? Why the socket connection can't be established?
I forgot I had asked this question... anyway I solved. It was just a matter of opening the right TCP ports for RabbitMQ:
22
15672
5672
I also changed the way I run celery, by using supervisor + django-supervisor in order to daemonize it properly :)
Related
I am having a serious issue with AWS elastic beanstalk and I don't know how to solve it.
I have deployed the DRF app in the elastic beanstalk.
My Django rest framework works fine in 127.0.0.1 but it is its giving 500 internal server error in the elastic beanstalk server.
(The log file is too big so not uploading here.)
The most prominent error lines from logfile are-
1. mod_wsgi (pid=3890):
Target WSGI script '/opt/python/current/app/beanalytic_project/wsgi.py' cannot
be loaded as Python module.
----------
2.mod_wsgi (pid=3890): Exception occurred processing WSGI script
'/opt/python/current/app/my_project/wsgi.py'.
----------
3.Traceback (most recent call last):
[Wed Nov 06 10:57:18.422431 2019] [:error] [pid 3890] [remote
172.31.18.188:71] File "/opt/python/current/app/my_project/wsgi.py", line
16, in <module>
[Wed Nov 06 10:57:18.422436 2019] [:error] [pid 3890] [remote
172.31.18.188:71] application = get_wsgi_application()
[Wed Nov 06 10:57:18.422443 2019] [:error] [pid 3890] [remote
172.31.18.188:71] File "/opt/python/run/venv/local/lib64/python3.6/site-
packages/django/core/wsgi.py", line 12, in get_wsgi_application
Please help. I really need it. Thank You.
The tutorial I followed https://www.youtube.com/watch?v=ypnEf7W8db0.
I have looked at every similar question about this and still can't figure out what's wrong. I'm try to set up a python REST service on my VPS alongside my wordpress site. I can get a "Hello world" wsgi file to run no problem, but when I point to my django rest wsgi file, I get a 500 server error.
My wordpress site is in /var/www/html/mysite/public_html, and the rest service is in /var/www/html/mysite/myrest. www-data has ownership of everything in the mysite folder. I've installed all dependencies, and started the project with python manage.py runserver just to make sure it's not missing anything.
This is my wsgi file.
import os
import sys
import site
site.addsitedir('/var/www/html/mysite/myrest/lib/python2.7/site-packages')
sys.path.append('/var/www/html/mysite/myrest')
os.environ['PYTHON_EGG_CACHE'] = '/var/www/html/mysite/.python-egg'
os.environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
Before it didn't have the site.addsitedir stuff, that got added as I tried different solutions.
There's some weird stuff going on in the apache logs, but I couldn't make sense of it.
[Sun Feb 19 20:39:33.697146 2017] [core:notice] [pid 26048] AH00094: Command line: '/usr/sbin/apache2'
[Sun Feb 19 20:41:30.804083 2017] [mpm_prefork:notice] [pid 26048] AH00169: caught SIGTERM, shutting down
[Sun Feb 19 20:41:31.707014 2017] [wsgi:warn] [pid 26721] mod_wsgi: Compiled for Python/2.7.11.
[Sun Feb 19 20:41:31.707037 2017] [wsgi:warn] [pid 26721] mod_wsgi: Runtime using Python/2.7.12.
[Sun Feb 19 20:41:31.709784 2017] [mpm_prefork:notice] [pid 26721] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Sun Feb 19 20:41:31.709801 2017] [core:notice] [pid 26721] AH00094: Command line: '/usr/sbin/apache2'
I'm pulling my hair out. Your help is greatly appreciated.
The problem was in my settings.py file. I managed to debug it by putting
import django
django.setup()
in various places throughout settings.py.
I pushed an update to my site earlier today, and when I tried to connect to it, received a Gateway Time-out error (503).
This is my error log :
[Wed Nov 04 01:34:26 2015] [error] [client 128.79.79.108] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
[Wed Nov 04 01:38:39 2015] [error] [client 66.249.79.153] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
[Wed Nov 04 01:39:26 2015] [error] [client 128.79.79.108] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
[Wed Nov 04 01:40:18 2015] [error] [client 109.190.112.58] Timeout when reading response headers from daemon process 'elandemdaemon': /home/python/home/elandem/edem/edem/wsgi.py
And here are the contents of my wsgi.py file :
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "edem.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I reverted my changes (minor things), but the issue remains. Was it just a coincidence that the issue happend right after an update ?
When I load the site with runsever 0.0.0.0:8000, it works fine.
Is there a step-by-step way to check where this issue may be occuring ?
I have a problem with django module named freetext.
There is no info how to install it in Django. I'm getting this error while trying to run Django on new server:
[Mon May 28 13:47:45 2012] [error] mod_wsgi (pid=27668): Exception occurred processing WSGI script '/var/www/vhosts/domain.co.uk/sites/somod/apache/django.wsgi'.
[Mon May 28 13:47:45 2012] [error] Traceback (most recent call last):
[Mon May 28 13:47:45 2012] [error] File "/usr/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Mon May 28 13:47:45 2012] [error] self.load_middleware()
[Mon May 28 13:47:45 2012] [error] File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Mon May 28 13:47:45 2012] [error] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Mon May 28 13:47:45 2012] [error] ImproperlyConfigured: Error importing middleware shop.cart.middleware: "No module named freetext"
How can I install this module?
In this way:
pip install -e https://github.com/howiworkdaily/django-freetext.git
Update, that doesn´t work because that app doesn´t have a setup.py, so clone it and put it in somewhere PYTHONPATH can find it, or better like a submodule.
Or just inside your django project:
git clone https://github.com/howiworkdaily/django-freetext.git freetext
at the same level of your manage.py
I'm developing application on Django, and ready to move to deployment server. I'm able to run a new django project on apache(I can see the welcome page).
However, when I copy my original project's files to apache project directory, I start getting errors. Here is a sample from apache/error.log.
[Wed Jan 26 19:22:08 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught ImportError while rendering: No module named charts
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4670): Exception occurred processing WSGI script '/srv/www/enpass/apache/django.wsgi'.
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] response = self.get_response(request)
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 141, in get_response
My django.wsgi file looks like
import os
import sys
path = '/srv/www'
if path not in sys.path:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'enpass.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I've changed all the paths in files to suit the new directory structure, so I'm pretty sure thats not the problem. FIY, I followed the steps given in this tutorial http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/
I figured it out myself. We need to add the project directory path to sys.path. The following code solved the problem in django.wsgi
path = '/srv/www/enpass'
if path not in sys.path:
sys.path.append(path)
Looks like you are missing the charts module..
install pip
sudo easy_install pip
list packages
pip freeze
do the same on the development machine and look for a chart module, then install it on the production server with
sudo pip install <packagename>