H
H
huko2015-10-11 21:45:12
Django
huko, 2015-10-11 21:45:12

How to restart django server from application?

It so happened that in one of the applications, after updating the data, you need to re-read all the settings by restarting the server. I restart the update of the wsgi.py file through my own function, the problem is that if you call the function from views.py, then the server goes down for a short time, which I successfully catch (ERR_EMPTY_RESPONSE). I don't understand how and where to insert some time.sleep(2) to avoid this.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vadim Shandrinov, 2015-10-11
@suguby

IMHO curve architecture - how it is possible to give to restart the server to the client? and if you are hacked and put in a restart loop?
You can read more about "It so happened that in one of the applications after updating the data you need to re-read all the settings through restarting the server" - you need to dig here. Maybe you need to store the variable part not in the settings, but in the database, for example?

S
sim3x, 2015-10-11
@sim3x

This may be needed only if you generate code and write it to a file "on the fly"
// purely theoretically, there is an option with uWSGI. Set touch-reload=/path/to/settings.py
uwsgi-docs.readthedocs.org/en/latest/Management.html
There are several ways to make uWSGI gracefully restart.

# using kill to send the signal
kill -HUP `cat /tmp/project-master.pid`
# or the convenience option --reload
uwsgi --reload /tmp/project-master.pid
# or if uwsgi was started with touch-reload=/tmp/somefile
touch /tmp/somefile

If a separate application is being created, then it is better to look towards deployment scripts

V
Vlad Zhivotnev, 2015-10-11
@inkvizitor68sl

It is possible through sys.exec (well, through sudo), but they only correctly tell you that you have chosen some rotten path.
Teach the application to update these settings on the fly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question