Created
February 22, 2017 02:49
-
-
Save wfsly/60a95eb9a04488217896cc801a833e7f to your computer and use it in GitHub Desktop.
fabric deploy server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
from fabric.api import env, cd, run | |
from fabric.colors import * | |
from fabric.contrib.console import confirm | |
import re | |
env.hosts = ['192.168.1.126'] | |
env.user = 'qducc' | |
env.password = '12345678' | |
def deploy_test_server(project): | |
if project == 'qdu': | |
project_path = '/home/qducc/qducc_backend/backend' | |
port = '8000' | |
else: | |
project_path = '/home/qducc/dev/etsong_property/backend' | |
port = '8001' | |
with cd(project_path): | |
print green('将从远程仓库下载master源代码') | |
run('git pull origin master') | |
# deleete .pyc | |
print green('删除项目下.pyc文件') | |
run('find ./ -name "*.pyc" | xargs rm -rf') | |
print green('进行数据库数据迁移') | |
run('./manage.py migrate') | |
print green('kill 已启动进程') | |
ls = 'lsof -i:' + port | |
try: | |
lsof = run(ls) | |
pattern = re.compile(r'\d+') | |
match = pattern.search(str(lsof)) | |
if match: | |
port_number = match.group() | |
run('kill ' + str(port_number)) | |
except: | |
pass | |
print green('重新启动服务器') | |
dep = 'gunicorn -b 0.0.0.0:'+ port +' wsgi:application' | |
run(dep) | |
def deploy_doc(project): | |
if project == 'qdu': | |
project_path = '/home/qducc/docs/dev_doc/qducc_doc' | |
elif project == 'ets': | |
project_path = '/home/qducc/docs/dev_doc/etsong_doc' | |
with cd(project_path): | |
print green('将从远程仓库下载master源代码') | |
run('git pull origin master') | |
print green('进入项目screen') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment