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.
Related
I am working a project, that creates an django app over a request. Since the webserver apache needs to be restarted to add new files created. I tried following:
1) Django request_complete Signals: This is not good way because I dont want my server to be restarting on every request complete
2) threading.Time:I tried to run a function with some delay so that it allows complete the current request.
This is not working giving following error:
RuntimeError at /apps/37f63340-2984-40b1-a728-1cf3d0820ae6/
threads can only be started once
Please suggest me way to solve this problem.
You tagged this with "webfaction" so I'm going to assume you're using WebFaction's default mod_wsgi setup.
If that's the case, then you can restart the mod_wsgi daemon processes, instead of restarting Apache itself, as described in the mod_wsgi documentation: Reloading Source Code
I have a website (panicselect.com), and I have made some changes to the python code which i pushed onto Github and then pulled onto my server, which seems to be successful. I have tried restarting the server, but it still seems to be running my older version of the code even though I have successfully pulled the new version. I believe this as some 'champions' are still missing and the rating seems to be calculated the old way, which is in contrast to what is on my localhost. Do you have an idea of what this could be? I'm running Ubuntu Linux on Digital Ocean with sendfile off and nginx uses Uwsgi to run the Py code.
To fully determine how to deploy changes to your production server, you must understand 2 things:
1. Most WSGI servers (including uWSGI) will load code on start, not on each execution.
That means, changes in your code won't be reflected immediately, because old code is still loaded into your WSGI server. It differs from PHP execution, where code is reloaded on every request. That means, you must restart your WSGI server when you want your new code to be loaded.
2. WSGI and nginx are NOT related
Yes, nginx will connect your WSGI server to outside world, but that's it! It doesn't manage your WSGI server. That means, you must restart your WSGI server by hand. Restarting nginx won't cause that.
Also it is good to note here: restarting nginx is not required, unless you've changed nginx configuration.
When the code for my python WSGI applicaiton changes should I use apache2's reload or graceful restart feature?
Currently we use reload, but have noticed that sometimes the application does not load properly and errors pertaining to missing modules are logged to the error files even though the modules have existed for a long time.
If you can, you should probably use graceful. But if your application is not exiting correctly you may have to force it with just restart.
For wsgi, you should try running in daemon mode. When it is running in daemon mode, you can restart your service just by touching the wsgi file and updating its timestamp. This will reload all the code without restarting apache.
Here is more info: http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
This is for django, but may be useful for your project: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
The 'reload' and 'graceful' would have the same effect as far as reloading your web application. If you are seeing issues with imports like you describe, it is likely to be an issue in your application code with you having import order dependencies or import cycles. One sees this a lot with people using Django. Suggest you actually post an example of the error you are getting.
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.
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.