gunicorn autoreload on source change

前端 未结 4 1875
太阳男子
太阳男子 2020-11-28 06:00

Finally I migrated my development env from runserver to gunicorn/nginx.

It\'d be convenient to replicate the autoreload feature of runserver to gunicorn, so the serv

4条回答
  •  萌比男神i
    2020-11-28 06:27

    I use git push to deploy to production and set up git hooks to run a script. The advantage of this approach is you can also do your migration and package installation at the same time. https://mikeeverhart.net/2013/01/using-git-to-deploy-code/

    mkdir -p /home/git/project_name.git
    cd /home/git/project_name.git
    git init --bare
    

    Then create a script /home/git/project_name.git/hooks/post-receive.

    #!/bin/bash
    GIT_WORK_TREE=/path/to/project git checkout -f
    source /path/to/virtualenv/activate
    pip install -r /path/to/project/requirements.txt
    python /path/to/project/manage.py migrate
    sudo supervisorctl restart project_name
    

    Make sure to chmod u+x post-receive, and add user to sudoers. Allow it to run sudo supervisorctl without password. https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/

    From my local / development server, I set up git remote that allows me to push to the production server

    git remote add production ssh://user_name@production-server/home/git/project_name.git
    
    # initial push
    git push production +master:refs/heads/master
    
    # subsequent push
    git push production master
    

    As a bonus, you will get to see all the prompts as the script is running. So you will see if there is any issue with the migration/package installation/supervisor restart.

提交回复
热议问题