Hot deployment using mod_wsgi,python and django on Apache - python

I have setup an Apache server with mod_wsgi, python_sql, mysql and django.
Everything works fine, except the fact that if I make some code changes, they do not reflect immidiately, though I thing that everything is compiled on the fly when it comes to python/mod_wsgi.
I have to shut down the server and come back again to see the changes.
Can someone point me to how hot-deployment can be achieved with the above setup??
Thanks,
Neeraj

This is covered by mod_wsgi documentation. See:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

Just touching the wsgi file allways worked for me.

Related

Internationalization (i18n) not rendered using flask-babel and apache with mod_wsgi on Ubuntu instance

I have a web application developed using python 2.7.6, flask and deployed on a Apache Ubuntu server.
For internationalization, the app uses the flask-babel package in order to translate into Thai. However, it seems that my translations/th/LC_messages/messages.po file is ignored.
It works perfectly in my localhost but not in the server. To force the selection of the locale, I use the code below:
#babel.localeselector
def get_locale():
return 'th'
It seems there is something that might be missing in my configuration file but couldn't figure it out.
If you have any ideas please feel free. Thank you.
I encountered this exact same issue! My babel translations were working fine when I ran the app locally, but on my apache server, none of the text was translating as expected.
After attempting a number of different fixes, I figured out that (for whatever reason), my custom get_locale localeselector override function was not getting used by the app when it ran on the apache server.
I ended up explicitly importing the get_locale function into the relevant view file, which resolved the issue.

Django/Apache code not reloading after restart of web server

I'm dealing with legacy code on Ubuntu server. I've encountered something weird: after Apache restarts (a full server restart), the site is still using old code, even if views.py was deleted.
Please, provide me some suggestions/tips - what might cause this server behavior?
I had this problem. In my case, running the following command solved it :
touch myproject/wsgi.py
No need to restart server or delete .pyc files. It's all explained in mod_wsgi docs.

problems doing the Django tutorial on Dreamhost using Passengers

I have looked and I could not find this question before, and it surprises me.
I am reasonably proficient in Python, and I used Dreamhost for a number of years. Now I would like to learn Django. They are finally supporting it using Passenger. Which I do not know what is.
Following the instructions on Dreamhost I installed Django. Then I started following the tutorial 01. This went well, except that I could not start the server (this in the tutorial) since the code was live on dreamhost. At the time this did not seem to make any difference. Then when I went on the second part of the tutorial I had to access the admin site. And it worked well going to myurl/admin/ , as it should. But here the problems started. According to the tutorial (here) I have to add a file in the poll application and then restart the server. But I never started the server in the first place, my code is running live on the web... but when I add a file the website the admin acts as if it does not see it.
Probably dreamhost has started its own server, and I don't know how to restart it. But I assume this is going to be a common problem when you run django on dreamhost. Every time you add a file you will have to tell the server to consider it.
So what should I do to let the server know about it?
Thanks,
Pietro
Here's the relevant section of the Passenger user's guide for restarting Passenger:
http://www.modrails.com/documentation/Users%20guide.html#_redeploying_restarting_the_ruby_on_rails_application
Eventually I got the answer from the DH support service. They told me to
pkill python
I did it. I also checked with
ps -aux
what process I was running. And indeed I could see the python process starting when I went to the page, and being killed when I pkilled it.
Thanks for all that helped.
I had the same problem with Passenger not reloading the Django server.
According to Django wiki page on Dreamhost, you can touch a "restart.txt" file that Passenger watches. If the timestamp on the file changes, Passenger restarts Django.
If you modified your application and your changes do not seem to be reflected, you may need to notify Passenger about your change by creating or modifying ~/example.com/tmp/restart.txt:
touch /home/user/example.com/tmp/restart.txt
Source: http://wiki.dreamhost.com/Django#Hints
For the tutorial, you should be working on a local machine, not a web server.

Have to Restart Apache When Using Django On Apache with mod_wsgi

I'm creating a web app with Django. Since I'm very familiar with Apache I setup my development environment to have Django run through Apache using mod_wsgi. The only annoyance I have with this is that I have to restart Apache everytime I change my code. Is there a way around this?
mod_wsgi is great for production but I think the included server is better for development.
Anyway you should read this about automatic reloading of source code.
I feel like this is really just one of those things most people deal with. It's really not that big of a deal. I made a bash script to make this as easy as possible. I name it 'ra' (reload apache) so it's short and quick. The following works for most apache installs (on UNIX-based systems):
#!/bin/bash
sudo /etc/init.d/apache2 reload
You could probably use some kind of tool to bind this to a key shortcut/foot pedeal/cron.

Restarting a Django application running on Apache + mod_python

I'm running a Django app on Apache + mod_python. When I make some changes to the code, sometimes they have effect immediately, other times they don't, until I restart Apache. However I don't really want to do that since it's a production server running other stuff too. Is there some other way to force that?
Just to make it clear, since I see some people get it wrong, I'm talking about a production environment. For development I'm using Django's development server, of course.
If possible, you should switch to mod_wsgi. This is now the recommended way to serve Django anyway, and is much more efficient in terms of memory and server resources.
In mod_wsgi, each site has a .wsgi file associated with it. To restart a site, just touch the relevant file, and only that code will be reloaded.
As others have suggested, use mod_wsgi instead. To get the ability for automatic reloading, through touching the WSGI script file, or through a monitor that looks for code changes, you must be using daemon mode on UNIX. A slight of hand can be used to achieve same on Windows when using embedded mode. All the details can be found in:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
You can reduce number of connections to 1 by setting "MaxRequestsPerChild 1" in your httpd.conf file. But do it only on test server, not production.
or
If you don't want to kill existing connections and still restart apache you can restart it "gracefully" by performing "apache2ctl gracefully" - all existing connections will be allowed to complete.
Use a test server included in Django. (like ./manage.py runserver 0.0.0.0:8080) It will do most things you would need during development. The only drawback is that it cannot handle simultaneous requests with multi-threading.
I've heard that there is a trick that setting Apache's max instances to 1 so that every code change is reflected immediately--but because you said you're running other services, so this may not be your case.

Categories

Resources