Elastic beanstalk / Django Cache intermittently displaying wrong value - django

I have a site deployed to Elastic Beanstalk -- I've written some data to a Django memory cache, and when retrieving it i get two different values.
It would seem to me that there are multiple instances, but looking at my control panel, there seems to only be one web instance running right now.
i output the value in a log message and i see there are multiple PIDs.
[Wed Oct 21 14:21:34.922493 2015] [:error] [pid 14335] WARNING:root:Cached: After tomorrow, Back to the Future will take place entirely in the past.
[Wed Oct 21 14:21:35.133714 2015] [:error] [pid 14337] WARNING:root:Cached: Bacon and eggs is a day's work for a chicken and a lifetime achievement for a pig.
[Wed Oct 21 14:21:35.319643 2015] [:error] [pid 14337] WARNING:root:Cached: Bacon and eggs is a day's work for a chicken and a lifetime achievement for a pig.
[Wed Oct 21 14:21:35.521985 2015] [:error] [pid 14335] WARNING:root:Cached: After tomorrow, Back to the Future will take place entirely in the past.
[Wed Oct 21 14:21:35.690560 2015] [:error] [pid 14336] WARNING:root:Cached: Bacon and eggs is a day's work for a chicken and a lifetime achievement for a pig.
It seems to randomly toggle between the two values/pids.
I'm sure there's only one web node running - is there some way there are multiple instances of the application running on a single node?

You have a single EC2 instance with a single webserver (Apache, by default). However, Apache will create more than one worker process, each of which will run a separate instance of your Django app. When you make a request to your server, either one of the worker processes may answer it, which is why you're seeing the two values arbitrarily.
If you need a single cache across your application, you'd be better suited looking at running Memcached or Redis locally (for a single EC2 node) or using Amazon's ElastiCache service.

Related

HTTP ERROR 500 While try to connect to RDS in EC2

I'm with a problem, always when I try to make a new account, login, or something else involving RDS, the page returns HTTP ERROR 500, I tried to make a script to only connect to the RDS using PDO, however I get error, it's clear that the problem is to connect in RDS in my EC2 instance, I really don't know what to do, I can make login in RDS using my EC2 instance in the console, it works, but using script it doesn't works, the page says HTTP ERROR 500
Please, I really need help, I want to use my RDS db with EC2, but it is not working and I don't know what to do
I already allowed my EC2 instance to connect to the RDS in the security group, but as I said, it only connects in command line, not in PHP script
[Thu Sep 03 02:15:59.100708 2020] [proxy_fcgi:error] [pid 10451] [client 52.247.193.244:45920] AH01071: Got error 'Primary script unknown\n'
[Thu Sep 03 12:10:11.913268 2020] [cgi:error] [pid 10477] [client 40.71.11.192:52180] AH02811: script not found or unable to stat: /var/www/cgi-bin/kerbynet
[Thu Sep 03 12:52:08.589937 2020] [cgi:error] [pid 11748] [client 200.22.90.64:15727] AH02811: script not found or unable to stat: /var/www/cgi-bin/kerbynet

Video Straming on raspberrypi using flask apche2and wsgi server

I have used flask app for straming video via raspberrypi camera. The code i used for flask app is here:
https://blog.miguelgrinberg.com/post/video-streaming-with-flask
In local server it is doing video stream but not on my website.
I am using apache2 server having wsgi file below:
flaskapp2.wsgi
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/FlaskApp2/FlaskApp2")
from ashish import app as application
application.secret_key ='1233883'
The structure of file system is :
/var/www/FlaskApp2/
flskapp2.wsgi
FlaskApp2/
ashish.py
camera_pi.py
templates/index.html
The ashish.py is the flask app which is doing stream.
The error log file in apache is:
[Wed Nov 23 15:17:17.458803 2016] [mpm_prefork:notice] [pid 783] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/2.7.9 configured -- resuming normal operations
[Wed Nov 23 15:17:17.459043 2016] [core:notice] [pid 783] AH00094: Command line: '/usr/sbin/apache2'
[Wed Nov 23 15:17:14.278353 2016] [wsgi:warn] [pid 662] mod_wsgi: Compiled for Python/2.7.8.
[Wed Nov 23 15:17:14.279359 2016] [wsgi:warn] [pid 662] mod_wsgi: Runtime using Python/2.7.9.
[Wed Nov 23 15:17:14.305871 2016] [mpm_prefork:notice] [pid 662] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/2.7.9 configured -- resuming normal operations
[Wed Nov 23 15:17:14.306169 2016] [core:notice] [pid 662] AH00094: Command line: '/usr/sbin/apache2'
[Wed Nov 23 15:17:16.502484 2016] [wsgi:warn] [pid 670] mod_wsgi: Compiled for Python/2.7.8.
[Wed Nov 23 15:17:16.504897 2016] [wsgi:warn] [pid 670] mod_wsgi: Runtime using Python/2.7.9.
[Wed Nov 23 15:17:16.531217 2016] [mpm_prefork:notice] [pid 670] AH00163: Apache/2.4.10 (Raspbian) mod_wsgi/4.3.0 Python/2.7.9 configured -- resuming normal operations
[Wed Nov 23 15:17:16.531502 2016] [core:notice] [pid 670] AH00094: Command line: '/usr/sbin/apache2'
On localhost it is working but not on my website is there any mistake in wsgi file or i need to add something.
You have a few possible issues when getting a 404 Not Found.
If that VirtualHost is not the only one in the Apache configuration file, then it will never be used. This is because you have set ServerName incorrectly. The ServerName directory should be set to a host name. Not a URL, not an IP address. Thus using:
ServerName https://7a78657b7a.dataplicity.io
is incorrect. It should be:
ServerName 7a78657b7a.dataplicity.io
It has to be a host name as Apache relies on it for name base virtual host matching against the Host header in the request. If it is wrong, then Apache will not know which is the correct VirtualHost to use. When this occurs Apache will fall back to sending the requests to whatever was the first VirtualHost definition it found when reading the Apache configuration files. Thus if this is not the first VirtualHost definition, it will never be used. If there is no similar URL handler set up in the first VirtualHost, you will get a 404.
The second is your WSGI application entry point in the WSGI script file pointed at by the WSGIScriptAlias directive, is not called application you will get a 404. You do appear to have it being called application, so you should be fine on this point and it shouldn't be the issue. There would have been a distinctive error message in the Apache error logs of this was the issue anyway.
The third is that the URL path you are using doesn't map to a route in the Flask application. There are actually two part to this. Because you are mounting at a sub URL in Apache, the URL path must at least start with /flask2. With that value it means you need to have a route in your Flask application which matches the root of the site. Normally in Flask that would mean you have a route for #app.route('/') but am not sure whether that still works when you have mounted your Flask application at a sub URL in Apache. You don't show your route code, so can't see what you have. You might at least try instead using /flask2/ in the URL. If your video feed isn't at the root of the Flask application but a sub URL such as set up by #app.route('/video_feed') as given in the post you link, then you should be using /flask2/video_feed as URL path. If you don't use the correct URL you will get a 404.
My whole configuration of files were right but as i was running flask applications under apache server ,apache was not able to acess pi camera because it was not having root access to pi.so,on local server it was working but not on my website when it was running on apache.

Deploy Pyramid App on AWS Elastic Beanstalk

I'm attempting to deploy my Pyramid Application on AWS via Elastic Beanstalk. The upload/deploy works fine but when I send a request to the application I'm met with the following error:
File "/opt/python/run/venv/lib/python3.4/site-packages/pkg_resources/__init__.py", line 839, in resolve
[Sat Jul 16 21:04:40.351021 2016] [:error] [pid 10837] [remote 76.202.70.172:28102] raise DistributionNotFound(req, requirers)
[Sat Jul 16 21:04:40.351110 2016] [:error] [pid 10837] [remote 76.202.70.172:28102] pkg_resources.DistributionNotFound: The 'MyAppName' distribution was not found and is required by the application
[Sat Jul 16 21:34:47.346311 2016] [:error] [pid 10837] [remote 76.202.70.172:28102] mod_wsgi (pid=10837): Target WSGI script '/opt/python/current/app/application.py' cannot be loaded as Python module.
...where "MyAppName" is the name of my application (aka the one I've developed and am attempting to use).
From what it looks like, my actual application is not installed during the app deployment. Typically, on a local machine, after developing the application you run:
pip install -e .
in order to install the actual application you are developing. I suppose my question, although it seems silly, is: How do I actually install the application I've written onto the ec2 instance during the upload/deploy process of Elastic Beanstalk? Is there something that should be included in requirements.txt to also install the application in which the requirements.txt exists? Is this done automatically? What am I missing here?

My Wamp is bugging down?

I installed mysql and wamp 2.4 in my server . I made my wamp automatically start upon startup and also disabled wampmysqld so that it will not conflict with mysql.
Then i put my wamp online .
Last month I can smoothly access my server in my LAN network.
But sometimes this week, I cannot access my server's localhost page on my LAN network. I have to open wamp again and and restart all services and its annoying . There are days that wamp will work the whole day and sometimes you need to restart all services again what seems to be the problem and how to solve this?
I open apache logfile and find this error
[Fri Mar 11 13:45:36.654882 2016] [core:notice] [pid 3200:tid 492] AH00094: Command line: 'c:\\wamp\\bin\\apache\\apache2.4.4\\bin\\httpd.exe -d C:/wamp/bin/apache/Apache2.4.4'
[Fri Mar 11 13:45:36.655882 2016] [mpm_winnt:notice] [pid 3200:tid 492] AH00418: Parent: Created child process 3568
[Fri Mar 11 13:45:37.149910 2016] [mpm_winnt:notice] [pid 3568:tid 300] AH00354: Child: Starting 150 worker threads.

avahi_entry_group_new() failed: Too many objects

I'm working on making a REST API for my research lab's database. I'm using the Django REST framework and I've gotten everything running smoothly on my local machine. All my code is in its own branch in our Mercurial repo. When I switch branches on our server, the website crashes with:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, root#localhost and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.
More information about this error may be available in the server error
log.
The error logs on our server look like this:
[Tue Feb 03 12:55:56 2015] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Tue Feb 03 12:55:56 2015] [notice] Digest: generating secret for digest authentication ...
[Tue Feb 03 12:55:56 2015] [notice] Digest: done
[Tue Feb 03 12:55:56 2015] [notice] Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 mod_ssl/2.2.15 OpenSSL/1.0.1e-fips mod_wsgi/3.2 Python/2.6.6 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[Tue Feb 03 12:56:11 2015] [error] avahi_entry_group_add_service_strlst("Lee on [server name]") failed: Local name collision
(this sort of error repeats many times)
[Tue Feb 03 12:56:13 2015] [error] avahi_entry_group_new() failed: Too many objects
(this error repeats many times.)
I've tried Googling the avahi errors to no avail. Anyone have any insight?
Because of the "too many objects" part of the error, I thought that it might somehow be related to not setting the pagination settings for the API. I only have a couple test objects on my local dev version of the database, but the actual database has tens of thousands. I set up pagination and tried again but it didn't change anything.
Turns out the culprit was not having the djangorestframework package installed for the correct version of Python on the server!? Hopefully this helps someone later down the line.