Answer the question
In order to leave comments, you need to log in
How to reload python (DJANGO) on server and update data on server after push??
Good day to all.
The site is built on Django, working with GIT.
During the day I write code and make commits. At the end of the working day, I push to master.
Unfortunately, my updates do not appear on the server, in any case, after updating the update link, I do not see it.
But it doesn't matter, I tell the boss that I uploaded push commits and he uploads them to the server.
He told me that I need to write a script that would be able to push to the server and reload Python in the north.
Help please, otherwise I'm tired of distracting my colleagues. Thanks
Answer the question
In order to leave comments, you need to log in
You need to make a hook on the server that will reboot the process after Push to your repo.
hook is the same script, but it does not push, but is only executed after Push has entered the repository.
You can write it yourself if you either have a very simple service, or have a high development skill and understanding how to properly reload the service.
But there is another way, run your project through UWSGI (it integrates very easily with Django), it has an option - reload, you can set it up so that when you change specific files, your service restarts correctly.
Gunicorn has similar mechanisms if you like it better, but I would recommend using UWSGI with Django
https://uwsgi-docs.readthedocs.org/en/latest/
You can use the ready-made application www.fabfile.org/installing.html ( https://github.com/fabric/fabric)
The bottom line is that you need to write a script with sequential execution of commands.
Here's how it's implemented for me.
The server is running nginx + uwsgi. (installation here https://habrahabr.ru/post/226419/)
A line has been added to the uwsgi.ini file (on Habré from the link above, this file is called mysite_uwsgi.ini)
# reload uwsgi
touch-reload=/opt/sitename/reload.txt
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from fabric.api import env, run, cd
env.hosts = ['[email protected]', ]
#Структура такая
# /
# + opt/
# + sitename/
# + env/ тут virtualenv
# + source/ тут лежит код
project_path = '/opt/sitename/'
source_path = '/opt/sitename/source/'
branch = ''
# Скрипт деплоя
def deploy():
# выполняются комманды для загрузки данных из репозитория
with cd(source_path):
run('mkdir -p tmp/')
run('hg pull')
run('hg update %s' % branch)
# после загрузки репозитория
# устанавливаются пакеты перечисленные в req.txt
# производятся миграции
# собирается статика
# теребим файл reload.txt, чтобы оповестить uwsgi об обновлении
with cd(project_path):
run('env/bin/pip install -r %sreq.txt' % source_path)
run('env/bin/python %smanage.py migrate' % source_path)
run('env/bin/python %smanage.py collectstatic --noinput' % source_path)
# run('env/bin/python %smanage.py compress' % source_path)
run('touch reload.txt')
fab deploy
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question