使用Faric+Git进行分布式代码管理
from fabric.api import *
from fabric.colors import * #服务器主机列表
#env.hosts=['username1@host1:port','username2@host2:port']
#如果多个服务器密码相同直接使用
#env.password='password'
#可以使用ssh密钥来代替密码访问远程主机(更安全),前提是需要将公钥保存在远程主机的authorized_keys文件中
#env.key_filename=‘~/.ssh/id_rsa' #若服务器之间密码不同,使用passwords变量存储键值对
#env.passwords = {'username1@host1:port':'password1','username2@host2:port':'password2'} #使用roledefs进行服务器角色分组
#env.roledefs = {
# 'role1': ['username1@host1:port'],['username2@host2:port']
# 'role2': ['['username3@host3:port']']
#} #称为任务函数,可在命令行使用fab local_update:msg=msg 直接调用
def local_update(msg):
#打印红色字体
print red('local host:ali_ibignose')
#打印绿色字体
print green('local git pushing...')
#lcd为本地的cd操作
with lcd('/home/omniREST/'):
#如果当前没有新的更改直接使用commit会终止任务进行,所以将此中断设置仅为输出警告信息
with settings(warn_only=True):
#local为在本地执行命令
local('git add *')
local('git commit -m "%s"' % msg)
local('git push -u origin master')
print green('local git push complete!') #parallel注解的作用是可以使函数并行执行,可用在多个服务器同时进行同一个任务函数
#@parallel
def local_docker_restart():
print red('local host:ali_ibignose')
print green('local docker restarting...')
local('docker restart omniREST ./root/run.sh')
print green('local docker restart complete!') #设置角色使用roles注解,那么该任务函数将会在所有角色为role1的机器上执行
#@roles('role1')
def remote1_update():
#也可直接在任务函数中指明连接主机的信息
env.user='username'
env.host_string='username@host:port'
env.password='password'
print red('remote host:nc_test')
print green('remote git pulling...')
#cd为远程cd操作
with cd('/home/omniREST/tomcat/webapps/ROOT'):
#run为远程执行命令操作
run('git pull origin master')
print green('remote git pull complete!')
print ''
print green('remote tomcat restarting...')
with cd('/home/omniREST/tomcat/bin'):
run('./shutdown.sh')
run('nohup ./startup.sh')
print green('remote tomcat restart complete!') def remote2_update():
print red('remote host:ibignose')
print green('remote git pulling...')
with cd('/data2/usr/ibignose/tomcat/webapps/ROOT'):
run('git pull origin master')
print green('remote git pull complete!')
print ''
print green('remote tomcat restarting...')
with cd('/data2/usr/ibignose/tomcat/bin'):
run('./shutdown.sh')
run('nohup ./startup.sh')
print green('remote tomcat restart complete!') #可以在命令行直接使用fab update:msg=msg 来调用所有任务函数
#执行流程为从上到下,一旦遇到终止性的错误将不会继续执行
def update(msg):
local_update(msg)
print ''
local_docker_restart
print ''
remote1_update()
print ''
remote2_update()
#遍历字典方式操作多服务器
dict_host={'ibignose':'root@42.62.50.218:22','nc_test':'root@54.223.196.153:22'}
dict_user={'ibignose':'root','nc_test':'root'}
dict_pwd={'ibignose':'richardg@b83a6fa8','nc_test':'T6yuj&hg'}
dict_path={'ibignose':'/data2/usr/ibignose/tomcat','nc_test':'/home/omniREST/tomcat'} def remote_update():
for hostname,host in dict_host.iteritems():
env.user='%s' % dict_user[hostname]
env.host_string='%s' % host
env.password='%s' % dict_pwd[hostname]
print red('remote hostname:%s' % hostname)
print green('remote git pulling...')
with cd('%s/webapps/ROOT' % dict_path[hostname]):
run('git pull origin master')
print green('remote git pull complete!')
print ''
print green('remote tomcat restarting...')
with cd('%s/bin' % dict_path[hostname]):
run('./shutdown.sh')
run('nohup ./startup.sh')
print green('remote tomcat restart complete!')
使用Faric+Git进行分布式代码管理的更多相关文章
- 分布式代码管理 tortoisehg mercurial
下载客户端: https://bitbucket.org/tortoisehg/files/downloads mercurial客户端下载:http://mercurial.s ...
- [Git] 谷歌的代码管理
copy from : http://www.ruanyifeng.com/blog/2016/07/google-monolithic-source-repository.html https:// ...
- Go语言在线培训哪里好?Git操作和代码管理
在实际的项目开发过程中,多人进行项目开发,需要涉及到代码管理和协同管理.这就需要使用到代码协同管理工具.在过去,大家都熟悉使用的是SVN软件,而现在Git代码仓库管理软件的使用更为广泛.在本系列实战项 ...
- 关于分布式代码管理工具git
一.安装 Step1 进入官网https://www.git-scm.com/download/下载,然后安装,一直“下一步”即可 Step2 验证是否安装成功,在任意地方右键,菜单中含有Git ...
- git是一种分布式代码管理工具,git通过树的形式记录文件的更改历史,比如: base'<--base<--A<--A' ^ | --- B<--B' 小米工程师常常需要寻找两个分支最近的分割点,即base.假设git 树是多叉树,请实现一个算法,计算git树上任意两点的最近分割点。 (假设git树节点数为n,用邻接矩阵的形式表示git树:字符串数组matrix包含n个字符串,每个字符串由字符'0
// ConsoleApplication10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...
- GIt如何进行代码管理
一:Git账号设置(仅第一次需设置): 1.首先打开GIt Bash 界面
- 分布式代码管理github
Git是世界上最先进的分布式版本的控制系统,特点是:简单大气上档次. Linus在1991年创建了开源的Linux,从此,Linux系统不断发展,已经成为最大的服务器系统软件了.
- git subtree模块化代码管理
Git Subtree 的原理 首先,你有两个伟大的项目——我们叫他P1项目.P2项目,还有一个牛逼的要被多个项目共用的项目——我们叫他S项目.我们通过简要讲解使用Subtree来同步代码的过程来解释 ...
- 使用Git Bash进行代码管理
前提是已经安装了GitBash,这个稍后再出教程 1.新建一个目录,存放下载下来的项目,我在D盘新建了一个“gitspace”文件夹,用来存放下载下来的项目 2.进入刚刚新建的文件夹,即进入“gits ...
随机推荐
- shell脚本(傻瓜式处理文件到指定分类)
前言 每一到两周,我大概会新增十多个甚至更多的资料文件,都是些最近遇到的一些问题的总结或者相关技术文档,但是资料都是在公司电脑上,拷贝到自己电脑上后,又得一个个去找一个这个应该放到哪个分类,个人感觉很 ...
- 【转】Spring Bean属性解析
转载自:http://wenku.baidu.com/view/30c7672cb4daa58da0114ae2.html Bean所以属性一览: <bean id="beanId&q ...
- Delphi New,Getmem,ReallocMem联系与区别
来自:http://www.cnblogs.com/jsrgren/archive/2011/10/31/2270353.html ---------------------------------- ...
- LNMP的基本配置
LNMP的基本配置cd /usr/local/nginx_php/etc/ > php-fpm.conf //清空php-fpm.conf vim ph ...
- 大数据量的Mysql数据库备份策略
Centos下mysql常用的三种备份方法 http://www.centoscn.com/CentOS/Intermediate/2013/0807/1160.html xtrabackup备份 h ...
- JSONObject常用的API
http://www.cnblogs.com/java-pan/archive/2012/04/07/jsonobject.html 1.介绍基于JSONObject 1.1的API 2.只介绍常用的 ...
- 只用120行Java代码写一个自己的区块链-4实现真正的p2p网络
在之前的文章中,我们模拟了节点网络通讯,很多朋友反馈说,他们想看真正的节点网络通讯而不是单节点的模拟.本章将满足你们.
- “pip failed to create process”的问题
增加python -m的方法能完美解决pip,easy_install 安装时报错:“pip failed to create process”的问题,据推测应该是64bit操作系统下会是如此. Wi ...
- 转载] magento 产品数据表结构
原文地址:http://blog.sina.com.cn/s/blog_9302097a010120l4.html 数据库-- 产品数据库表结构分析 product 1数据库实体表:catalog_p ...
- 浙江省第十二届省赛 Beauty of Array(思维题)
Description Edward has an array A with N integers. He defines the beauty of an array as the summatio ...