Reload django wsgi scripts without root - django

I have an install of django on apache using embedded wsgi. I DON'T have root on the machine.
How can I tell apache to reload the python instance when I deploy new source code?
I tried removing all the .pyc files and it still is running the old code.

If you are running mod_wsgi in daemon mode with apache, you may not have to restart apache to get it to reload.
I just touch my wsgi file (unix: touch updates the 'saved date' of a file) and apache reloads it on next access/web-hit.
See http://code.google.com/p/modwsgi/wiki/QuickConfigurationGuide
... as long as you can alter the timestamp on the WSGI script.

http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
This article about reloading source code with mod_wsgi goes into how to reload source code, and even how to create a monitor script to automatically reload the daemon when you make source changes. It's really good for setting up a development environment using mod_wsgi.

Related

Do I need to restart apache each time after changing code

I am deploying a Django app on webfaction. All code are uploaded, but sometimes there are still some modification I need to make. My workflow is edit local file in Pycharm and sync the change to remote server (Apache). So, for example, do I need to restart apache every time after changing views.py for the change to take effects?
If you are using modpython yes, you have to reload apache every time or your modules will not be reloaded.
If you are using apache and mod_wsgi then touching the wsgi module is enough.
As other already suggested nginx + gunicorn (or better nginx + uwsgi) are better options than apache + mod_python to serve your django app.
In fact, you do not have to, you just have to « touch » the wsgi.py file (if you are using the mod_wsgi apache2 module). You can do it by uploading the wsgi.py file every time you upload something.

Does uWSGI need to be restarted when Django code changes?

I'm working on a Django webapp that's running under nginx and uWSGI. When I deploy new Django code (e.g., settings.py), do I need to restart uWSGI? If so, why?
Background: I had a scenario where I updated settings.py and some other code and deployed it. I did not see the changes in the webapp behavior until I restarted uWSGI.
Yes, you need to restart the uWSGI process.
Python keeps the compiled code in memory so it won't get re-read until the process restarts. The django development server (manage.py runserver) actively monitors files for changes, but that won't happen by default with other servers. If you want to enable automatic reloading in uWSGI, the touch-reload and py-auto-reload uWSGI arguments might help.

Is it possible to reload the view without restarting Django?

After changing the view function without runserver again, and press F5 to refresh the page, Django will not reload the new view but use the previous one. but if you change the template, Django always uses the new one.
So, Is there a way to make Django reload the view every time the user refresh the page, I think that is very convenient for develop to modify the view function frequently.
If you are running django using the dev server (./manage.py runserver) then it will always reload when it detects any code changes. This is even more efficient than reloading with every request. If you make a change, it reloads when it needs to.
If you are running a production server (nginx, apache, etc) and you want code-reload, then you need to add something to your wsgi module to detect code changes.
Code reloading with apache: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
Code reloading with uwsgi: http://projects.unbit.it/uwsgi/wiki/TipsAndTricks
It is a known issue with PyDev. I would suggest running the server from terminal/cmd.
cd to your project directory where manage.py is present and run the server using
python manage.py runserver
You don't need to run the project from eclipse menu.
Any changes made in eclipse would be reflected as soon as they are made.
If you are running Django as a WSGI application in daemon mode you just need to touch the wsgi.py for your site and it will reload the application next time there is a request. (So no need for any special options).
I noticed it is a setting in pyDev run configurations. I wonder why but it seems --noreload is configured by default. So I edit arguments of run settings and now the server is reloading also when editing views.
Try using gunicorn or nginx as running server... They dont restart on code change
try typing
gunicorn --bind 0.0.0.0:8080 app.wsgi:application

how to restart single apache site on a ubuntu vps rather than all sites

I've got a ubuntu vps and apache mod wsgi installed and serving my django sites.
however i have to restart all of apache rather than the site i have amended and its going to be a bit shonky if i tell clients that i have restarted their site cos i updated another site.
is there a tutorial somewhere to teach me how to configure this? i couldnt find one in googles keywords soup.
I'm already using virtualenvs if it helps.
Assuming you use mod_wsgi in daemon mode on UNIX/Apache 2.X system to run Django and have shell access to your machine all you need to do is touch the wsgi configuration for your project.
touch your_project.wsgi
See mod_wsgi documentation on Reloading Source Code and Django - mod_wsgi wiki for more references.

Apache Django Mod_Wsgi Sessions Development Environment

I'd like to know how I can maintain sessions while developing on my local machine (django, apache, mod-wsgi).
Each time I make updates to python code I need to restart Apache for the changes to take effect.
Read the documentation. See:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode
It explains in a great amount of detail about source code reloading in Apache/mod_wsgi.
Just touching the WSGI script file will not do anything if you aren't use mod_wsgi in the correct mode.
And yes you can use Apache/mod_wsgi as a development server if you set it up with daemon mode and code change monitor as documented in that page.
As for MaxRequestsPerChild, that is not recommended and will only work in embedded mode of mod_wsgi and not in daemon mode.
You only need to touch your WSGI script for the changes to take effect.
Put this in your Apache conf file.
MaxRequestsPerChild 1
This will force Apache to reload the python files after each request.