📜 ⬆️ ⬇️

Django: running with xinetd

So, another way to start Django. But why? After all, what are some ways to start there. It would seem for every taste. Justification and description - under the cut.



Introduction


')
I conceived one idea. Namely, use web applications as applications on your computer. Since I work with Python / Django, it’s natural to write applications using them.

What is needed for this? You need to run a web application with a minimum of unnecessary work. Everything seems to be there, Django can work without a database server (using SQLite), there is a built-in devserver, i.e. You can run web applications without installing and configuring a web server.

But it turned out that if everything is fine with SQLite, then working using the built-in devserver is not so convenient. It needs to be started manually, that will agree, excess gestures. And it would be desirable that when clicking on a link, everything starts working as an automatic machine.

Of course, you can run devserver at system startup, using startup scripts. But it is somehow ugly, eats resources and slows the start of the company. And if there are many such applications?

So, what do you want? In order for a web application to start working when addressing by its address, and in the absence of references it would lie quietly to itself on the hard disk.

Proposed Solution



Then I remembered xinetd. This server is doing something that is very similar to my task:



Everything is good, only here is the standard input and output, and Django communicates with the web server using the WSGI protocol.

Script



So, you need to write a script that, on the one hand, communicates with xinetd through stdin / stdout, and on the other hand, with my application on Django, via WSGI.

The script was written and the first version is posted on GitHub. Maybe it will interest someone, welcome.

You can download the script on GitHub: django-xinetd

Installation and configuration are described in the README.

Conclusion



Of course, the performance of such a solution is lower than with the use of a web server, but it suits me perfectly.

This is the first version and of course quite raw. But for the simplest cases you can use.

I almost forgot, as the platform used Linux (Ubuntu). xinetd is set by the command:

apt-get install xinetd 


The script is written and tested with Django v1.4. This is important, since in previous versions work with static files is different. With earlier versions, static files will not be served.

Source: https://habr.com/ru/post/153165/


All Articles