Dmi*_*kiy 211
虽然这是一个老问题,但只是为了保持一致性 - 因为版本19.0 gunicorn有--reload选择权.所以没有第三方工具需要更多.
Dav*_*gac 20
一种选择是使用--max-requests将每个生成的进程限制为仅通过添加--max-requests 1到启动选项来为一个请求提供服务.每个新生成的进程都应该看到您的代码发生了变化,并且在开发环境中,每个请求的额外启动时间应该可以忽略不计.
hob*_*obs 10
Bryan Helmig想出了这个并且我将其修改为使用run_gunicorn而不是gunicorn直接启动,以便可以将这3个命令剪切并粘贴到django项目根文件夹中的shell中(激活你的virtualenv):
pip install watchdog -U
watchmedo shell-command --patterns="*.py;*.html;*.css;*.js" --recursive --command='echo "${watch_src_path}" && kill -HUP `cat gunicorn.pid`' . &
python manage.py run_gunicorn 127.0.0.1:80 --pid=gunicorn.pid
Run Code Online (Sandbox Code Playgroud)
我使用 git push 部署到生产环境并设置 git hooks 来运行脚本。这种方法的优点是您还可以同时进行迁移和软件包安装。 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
Run Code Online (Sandbox Code Playgroud)
然后创建一个脚本/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
Run Code Online (Sandbox Code Playgroud)
确保chmod u+x post-receive将用户添加到 sudoers。允许它在sudo supervisorctl没有密码的情况下运行。 https://www.cyberciti.biz/faq/linux-unix-running-sudo-command-without-a-password/
从我的本地/开发服务器,我设置git remote允许我推送到生产服务器
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
Run Code Online (Sandbox Code Playgroud)
作为奖励,您将在脚本运行时看到所有提示。所以你会看到迁移/包安装/主管重启是否有任何问题。
| 归档时间: |
|
| 查看次数: |
41168 次 |
| 最近记录: |