自己寫的fabric指令碼
功能:使用fabric自動化發版
點選(此處)摺疊或開啟
-
#-*-coding:utf8-*-
-
from fabric.api import *
-
import subprocess
-
import os
-
import sys
-
import glob
-
import shutil
-
-
env.roledefs = {
-
'cz-oms-core':['czoms@10.2.88.47','czoms@10.2.88.48'],
-
'cz-oms-core-new':['czoms@10.2.88.37','czoms@10.2.88.46'],
-
'cz-oms-core-new1':['czoms@10.2.88.40','czoms@10.2.88.41'],
-
'cz':['appuser@10.2.88.30']
-
}
-
-
-
-
env.passwords = {
-
'czoms@10.2.88.47:22':'fdfdfsdf',
-
'czoms@10.2.88.48:22':'fdfdfsdf',
-
'czoms@10.2.88.37:22':'fdfdfsdf',
-
'czoms@10.2.88.46:22':'fdfdfsdf',
-
'czoms@10.2.88.40:22':'fdfdfsdf',
-
'czoms@10.2.88.41:22':'fdfdfsdf',
-
'appuser@10.2.88.30:22':'appuser@0630',
-
}
-
-
-
#通用函式
-
def unzip():
-
with lcd('patch'):
-
local('winrar x *.zip')
-
-
#Update SVN
-
def UpdateSVN(path):
-
p = subprocess.Popen(['svn','update',path],shell=True,stdout=subprocess.PIPE)
-
print p.stdout.readlines()
-
-
-
-
#根據filelist生成發版目錄
-
def faban_dir():
-
count = 0
-
with open('filelist.txt','r') as f:
-
for line in f:
-
if line.startswith('bj-oms-api'):
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-oms-api/src/main/java/','../online_svn/bj-oms/bj-oms-api/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-oms-api/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-oms-api/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-api/target/classes/','patch/bj-oms-api/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
elif line.startswith('bj-oms-domain'):
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-oms-domain/src/main/java/','../online_svn/bj-oms/bj-oms-domain/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-oms-domain/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-oms-domain/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-domain/target/classes/','patch/bj-oms-domain/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
elif line.startswith('bj-oms-core-new1'): #位置1,不可調換,因為bj-oms-core包含bj-oms-core-new1
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-oms-core-new1/src/main/java/','../online_svn/bj-oms/bj-oms-core-new1/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-oms-core-new1/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-oms-core-new1/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-core-new1/target/classes/','patch/bj-oms-core-new1/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
elif line.startswith('bj-oms-core'): #位置2,不可調換,因為bj-oms-core包含bj-oms-core-new1
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-oms-core/src/main/java/','../online_svn/bj-oms/bj-oms-core/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-oms-core/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-oms-core/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-core/target/classes/','patch/bj-oms-core/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
elif line.startswith('bj-oms-rest'):
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-oms-rest/src/main/java/','../online_svn/bj-oms/bj-oms-rest/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-oms-rest/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-oms-rest/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-rest/target/classes/','patch/bj-oms-rest/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
elif line.startswith('bj-oms-jobs'):
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-oms-jobs/src/main/java/','../online_svn/bj-oms/bj-oms-jobs/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-oms-jobs/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-oms-jobs/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-oms/bj-oms-jobs/target/classes/','patch/bj-oms-jobs/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
elif line.startswith('bj-tran'):
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-tran/src/main/java/','../online_svn/bj-tran/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-tran/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-tran/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-tran/target/classes/','patch/bj-tran/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
-
elif line.startswith('bj-whm-rest'):
-
#filelist檔案路徑預處理
-
classpath_filename = line.replace('bj-whm-rest/src/main/java/','../online_svn/bj-whm-rest/target/classes/')
-
classpath_filename = classpath_filename.replace('.java','.class')
-
classpath_filename = classpath_filename.replace('\n','') #去掉換行符
-
#構造patch目錄結構
-
patchpath_filename = line.replace('bj-whm-rest/src/main/java/','')
-
patchpath_filename = patchpath_filename.replace('.java','.class')
-
patchpath_filename = patchpath_filename.replace('\n','')
-
patchpath_filename = 'patch/' + 'bj-whm-rest/' + patchpath_filename
-
patchpath = os.path.dirname(patchpath_filename)
-
#如果patch目錄不存在,就建立目錄
-
try:
-
os.listdir(patchpath)
-
except WindowsError:
-
os.makedirs(patchpath) #makedirs可以在windows 的patch目錄下遞迴建立資料夾
-
#複製父類到patch目錄下
-
parentclass_path_filename = classpath_filename
-
patchpath_filename = patchpath_filename
-
print "複製svn class檔案到patch目錄: %s ---> %s " % (parentclass_path_filename,patchpath_filename)
-
shutil.copy(parentclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功***************" % count
-
#用glob尋找子類
-
path_filename = os.path.split(classpath_filename) #split:返回一個二元組,包含檔案的路徑與檔名
-
filename_splitext = os.path.splitext(path_filename[1]) #去掉副檔名
-
subclass_path_filenames = glob.glob('%s/%s$*' % (path_filename[0],filename_splitext[0]))
-
#把子類複製到patch目錄下
-
for subclass_path_filename in subclass_path_filenames:
-
subclass_path_filename = subclass_path_filename.replace('\\',r'/')
-
patchpath_filename = subclass_path_filename.replace('../online_svn/bj-whm-rest/target/classes/','patch/bj-whm-rest/')
-
print "複製svn subclass檔案到patch目錄: %s ---> %s " % (subclass_path_filename,patchpath_filename)
-
shutil.copy(subclass_path_filename,patchpath_filename)
-
count += 1
-
print "***********第%s個檔案複製成功,注意該檔案是子類哦^_^ *****************************************" % count
-
-
-
else:
-
print "%s:該專案沒有配置,請聯絡管理員" % line
-
sys.exit()
-
-
-
#down jar包
-
@hosts('czoms@10.2.88.47')
-
def download_bj_oms_api_jar():
-
get('/opt/bj-oms-core/lib/bj-oms-api-1.0-SNAPSHOT.jar','patch/bj-oms-api/')
-
-
@hosts('czoms@10.2.88.47')
-
def download_bj_oms_domain_jar():
-
get('/opt/bj-oms-core/lib/bj-oms-domain-1.0-SNAPSHOT.jar','patch/bj-oms-domain/')
-
-
@hosts('czoms@10.2.88.40')
-
def download_bj_oms_core_new1_jar():
-
get('/opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar','patch/bj-oms-core-new1/')
-
-
@hosts('appuser@10.2.88.30')
-
def download_bj_oms_rest_jar():
-
get('/opt/bj-oms-rest/lib/bj-oms-rest-1.0-SNAPSHOT.jar','patch/bj-oms-rest/')
-
-
@hosts('appuser@10.2.88.30')
-
def download_bj_oms_job_jar():
-
get('/opt/bj-oms-job/lib/bj-oms-job-1.0-SNAPSHOT.jar','patch/bj-oms-jobs/')
-
-
@hosts('czoms@10.2.88.47')
-
def download_bj_oms_core_jar():
-
get('/opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar','patch/bj-oms-core/')
-
-
-
#替換jar包裡面的檔案
-
def replace_file_to_local_bj_oms_api_jar():
-
with lcd('patch/bj-oms-api/'):
-
local('jar -uvf bj-oms-api-1.0-SNAPSHOT.jar * ')
-
'''
-
def replace_file_to_local_bj_oms_core_new1_jar():
-
with lcd('patch/bj-oms-core-new1/'):
-
local('jar -uvf bj-oms-core-1.0-SNAPSHOT.jar * ')
-
'''
-
-
def replace_file_to_local_bj_oms_domain_jar():
-
with lcd('patch/bj-oms-domain/'):
-
local('jar -uvf bj-oms-domain-1.0-SNAPSHOT.jar * ')
-
-
def replace_file_to_local_bj_oms_job_jar():
-
with lcd('patch/bj-oms-job/'):
-
local('jar -uvf bj-oms-job-1.0-SNAPSHOT.jar * ')
-
-
def replace_file_to_local_bj_oms_rest_jar():
-
with lcd('patch/bj-oms-rest/'):
-
local('jar -uvf bj-oms-rest-1.0-SNAPSHOT.jar * ')
-
-
def replace_file_to_local_bj_oms_core_jar():
-
with lcd('patch/bj-oms-core/'):
-
local('jar -uvf bj-oms-core-1.0-SNAPSHOT.jar * ')
-
-
-
-
-
#backup
-
@hosts('czoms@10.2.88.47')
-
def backup_bj_oms_api_jar():
-
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-api-1.0-SNAPSHOT.jar /backup/$dir1')
-
puts('bj-oms-api-1.0-SNAPSHOT.jar包備份到了10.2.88.47的/backup目錄下')
-
-
@hosts('czoms@10.2.88.47')
-
def backup_bj_oms_domain_jar():
-
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-domain-1.0-SNAPSHOT.jar /backup/$dir1')
-
puts('bj-oms-domain-1.0-SNAPSHOT.jar包備份到了10.2.88.47的/backup目錄下')
-
-
@hosts('czoms@10.2.88.40')
-
def backup_bj_oms_core_new1_jar():
-
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar /backup/$dir1')
-
puts('bj-oms-core-1.0-SNAPSHOT.jar包備份到了10.2.88.40的/backup目錄下')
-
-
@hosts('appuser@10.2.88.30')
-
def backup_bj_oms_rest_jar():
-
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-rest/lib/bj-oms-rest-1.0-SNAPSHOT.jar /backup/$dir1')
-
puts('bj-oms-rest-1.0-SNAPSHOT.jar包備份到了10.2.88.30的/backup/目錄下')
-
-
@hosts('appuser@10.2.88.30')
-
def backup_bj_oms_job_jar():
-
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/bj-oms-job/$dir1 && cp -a /opt/bj-oms-job/lib/bj-oms-job-1.0-SNAPSHOT.jar /backup/bj-oms-job/$dir1')
-
puts('bj-oms-job-1.0-SNAPSHOT.jar包備份到了10.2.88.30的/backup/目錄下')
-
-
@hosts('appuser@10.2.88.30')
-
def backup_bj_web():
-
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/tomcat-oms/webapps/bj-web /backup/$dir1')
-
puts('bj-web包備份到了10.2.88.30的/backup/目錄下')
-
-
@hosts('czoms@10.2.88.47')
-
def backup_bj_oms_core_jar():
-
run('dir1=$(date +%Y%m%d%H%M%S) && mkdir /backup/$dir1 && cp -a /opt/bj-oms-core/lib/bj-oms-core-1.0-SNAPSHOT.jar /backup/$dir1')
-
puts('bj_oms_core包備份到了10.2.88.30的/backup/目錄下')
-
-
-
#發版,上傳jar包
-
@hosts('czoms@10.2.88.47','czoms@10.2.88.48','czoms@10.2.88.37','czoms@10.2.88.46','czoms@10.2.88.40','czoms@10.2.88.41')
-
def put_bj_oms_api_jar_4748_3746_4041():
-
with lcd ('patch/bj-oms-api/'):
-
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib/')
-
-
@hosts('appuser@10.2.88.30')
-
def put_bj_oms_api_jar_30():
-
with lcd ('patch/bj-oms-api/'):
-
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
-
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
-
put('bj-oms-api-1.0-SNAPSHOT.jar','/opt/tomcat-oms/webapps/bj-web/WEB-INF/lib')
-
-
-
@hosts('czoms@10.2.88.47','czoms@10.2.88.48','czoms@10.2.88.37','czoms@10.2.88.46','czoms@10.2.88.40','czoms@10.2.88.41')
-
def put_bj_oms_domain_jar_4748_3746_4041():
-
with lcd ('patch/bj-oms-domain/'):
-
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')
-
-
@hosts('appuser@10.2.88.30')
-
def put_bj_oms_domain_jar_30():
-
with lcd ('patch/bj-oms-domain/'):
-
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
-
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
-
put('bj-oms-domain-1.0-SNAPSHOT.jar','/opt/tomcat-oms/webapps/bj-web/WEB-INF/lib')
-
-
-
@roles('cz-oms-core-new1')
-
def put_bj_oms_core_new1_jar():
-
with lcd ('patch/bj-oms-core-new1/'):
-
put('bj-oms-core-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')
-
-
@roles('cz')
-
def put_bj_oms_rest_jar():
-
with lcd ('patch/bj-oms-rest/'):
-
put('bj-oms-rest-1.0-SNAPSHOT.jar','/opt/bj-oms-rest/lib')
-
-
@roles('cz')
-
def put_bj_oms_job_jar():
-
with lcd ('patch/bj-oms-jobs/'):
-
put('bj-oms-job-1.0-SNAPSHOT.jar','/opt/bj-oms-job/lib')
-
-
@roles('cz')
-
def put_bj_web():
-
with lcd ('patch/'):
-
put('bj-web.zip','/opt/tomcat-oms/webapps')
-
run('cd /opt/tomcat-oms/webapps && unzip -o bj-web.zip && rm -rf bj-web.zip')
-
-
@roles('cz-oms-core')
-
def put_bj_oms_core_jar():
-
with lcd ('patch/bj-oms-core'):
-
put('bj-oms-core-1.0-SNAPSHOT.jar','/opt/bj-oms-core/lib')
-
-
-
#重啟服務
-
@roles('cz-oms-core')
-
def stop_cz_oms_core_4748():
-
sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)
-
-
@roles('cz-oms-core')
-
def start_cz_oms_core_4748():
-
sudo('/opt/bj-oms-core/bin/start.sh',pty=False)
-
-
-
-
@roles('cz-oms-core-new')
-
def stop_cz_oms_core__new_3746():
-
sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)
-
-
@roles('cz-oms-core-new')
-
def start_cz_oms_core__new_3746():
-
sudo('nohup /opt/bj-oms-core/bin/start.sh &',pty=False)
-
-
-
-
@roles('cz-oms-core-new1')
-
def stop_cz_oms_core__new1_4041():
-
sudo('/opt/bj-oms-core/bin/stop.sh',pty=False)
-
-
@roles('cz-oms-core-new1')
-
def start_cz_oms_core__new1_4041():
-
sudo('/opt/bj-oms-core/bin/start.sh',pty=False)
-
-
-
-
-
@roles('cz')
-
def stop_cz_bj_oms_rest_30():
-
sudo('/opt/bj-oms-rest/bin/stop.sh',pty=False)
-
-
@roles('cz')
-
def start_cz_bj_oms_rest_30():
-
sudo('nohup /opt/bj-oms-rest/bin/start.sh &',pty=False)
-
-
-
-
@roles('cz')
-
def stop_cz_bj_oms_job_30():
-
sudo('/opt/bj-oms-job/bin/stop.sh',pty=False)
-
-
@roles('cz')
-
def start_cz_bj_oms_job_30():
-
sudo('/opt/bj-oms-job/bin/start.sh',pty=False)
-
-
-
-
@roles('cz')
-
def stop_cz_tomcat_oms_30():
-
sudo('/opt/tomcat-oms/bin/shutdown.sh',pty=False)
-
-
@roles('cz')
-
def start_cz_tomcat_oms_30():
-
sudo('/opt/tomcat-oms/bin/start.sh',pty=False)
-
-
-
-
-
-
-
-
-
#主程式
-
if __name__ == '__main__':
-
#Update SVN
-
while True:
-
temp = str(raw_input('1) 請問你要Update SVN嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin Update SVN..."
-
UpdateSVN('../online_svn/bj-oms/bj-oms-api')
-
UpdateSVN('../online_svn/bj-oms/bj-oms-core')
-
UpdateSVN('../online_svn/bj-oms/bj-oms-core-new')
-
UpdateSVN('../online_svn/bj-oms/bj-oms-core-new1')
-
UpdateSVN('../online_svn/bj-oms/bj-oms-domain')
-
UpdateSVN('../online_svn/bj-oms/bj-oms-jobs')
-
UpdateSVN('../online_svn/bj-oms/bj-oms-rest')
-
UpdateSVN('../online_svn/bj-tran')
-
UpdateSVN('../online_svn/bj-whm')
-
break
-
elif tips == 'no':
-
break
-
#刪除patch目錄下所有內容
-
while True:
-
temp = str(raw_input('2)刪除patch目錄下所有目錄嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
for line in os.listdir('patch'):
-
shutil.rmtree('patch/%s' % line)
-
break
-
elif tips == 'no':
-
break
-
-
#提示是否eclipse編譯程式碼
-
while True:
-
temp = str(raw_input('3) 提示:請問你手工透過eclse編譯css程式碼了嗎[yes/no]:'))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
break
-
elif tips == 'no':
-
break
-
-
-
#根據filelist生成發版目錄
-
while True:
-
temp = str(raw_input('4)根據filelist生成發版目錄嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin generate faban dir..."
-
faban_dir()
-
break
-
elif tips == 'no':
-
break
-
-
-
#unzip
-
while True:
-
temp = str(raw_input('5)解壓zip包到本地patch目錄嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin unzip jar to patch dir..."
-
output = subprocess.check_output(['fab','unzip'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
break
-
elif tips == 'no':
-
break
-
-
#download jar to localpath
-
while True:
-
temp = str(raw_input('6)把jar包下載到本地的patch目錄嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin download jar to patch dir..."
-
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
-
for index,item in enumerate(dirs,1):
-
if item == 'bj-oms-api':
-
print "%d: %s is downoading..." % (index,item)
-
output = subprocess.check_output(['fab','download_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows時可以關閉cmd視窗的回顯
-
print output
-
elif item == "bj-oms-core-new1":
-
print "%d: %s is downoading..." % (index,item)
-
output = subprocess.check_output(['fab','download_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == "bj-oms-rest":
-
print "%d: %s is downoading..." % (index,item)
-
output = subprocess.check_output(['fab','download_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == "bj-oms-jobs":
-
print "%d: %s is downoading..." % (index,item)
-
output = subprocess.check_output(['fab','download_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == "bj-oms-domain":
-
print "%d: %s is downoading..." % (index,item)
-
output = subprocess.check_output(['fab','download_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == "bj-oms-core":
-
print "%d: %s is downoading..." % (index,item)
-
output = subprocess.check_output(['fab','download_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == "bj-web":
-
pass
-
else:
-
print('%s下載失敗,因為該檔案沒有在發版程式裡面配置,請聯絡管理員') % item
-
sys.exit()
-
break
-
elif tips == 'no':
-
break
-
-
-
-
#replace file to jar
-
while True:
-
temp = str(raw_input('7)替換jar包裡面的配置檔案嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin replace class file from jar ..."
-
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
-
for index,item in enumerate(dirs,1):
-
if item == 'bj-oms-api':
-
print "%d: %s is replacing jar now..." % (index,item)
-
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == "bj-oms-core-new1":
-
while True:
-
temp = str(raw_input('注意:因bj-oms-core-new1包裡面有重複檔案,所以需要手工更新jar包裡面的內容,你更新了嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
break
-
elif tips == 'no':
-
break
-
elif item == 'bj-oms-domain':
-
print "%d: %s is replacing jar now..." % (index,item)
-
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-job':
-
print "%d: %s is replacing jar now..." % (index,item)
-
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-rest':
-
print "%d: %s is replacing jar now..." % (index,item)
-
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-core':
-
print "%d: %s is replacing jar now..." % (index,item)
-
output = subprocess.check_output(['fab','replace_file_to_local_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
break
-
elif tips == 'no':
-
break
-
-
-
-
-
#backup jar
-
while True:
-
temp = str(raw_input('8)在正式發版前希望備份遠端伺服器的jar包嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin backup jar to /backup..."
-
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
-
for index,item in enumerate(dirs,1):
-
if item == 'bj-oms-api':
-
print "%d: %s is backuping..." % (index,item)
-
output = subprocess.check_output(['fab','backup_bj_oms_api_jar'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows時可以關閉cmd視窗的回顯
-
print output
-
print
-
elif item == 'bj-oms-domain':
-
print "%d: %s is backuping..." % (index,item)
-
output = subprocess.check_output(['fab','backup_bj_oms_domain_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-core-new1':
-
print "%d: %s is backuping..." % (index,item)
-
output = subprocess.check_output(['fab','backup_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-rest':
-
print "%d: %s is backuping..." % (index,item)
-
output = subprocess.check_output(['fab','backup_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-jobs':
-
print "%d: %s is backuping..." % (index,item)
-
output = subprocess.check_output(['fab','backup_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-web':
-
print "%d: %s is backuping..." % (index,item)
-
output = subprocess.check_output(['fab','backup_bj_web'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-core':
-
print "%d: %s is backuping..." % (index,item)
-
output = subprocess.check_output(['fab','backup_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
break
-
elif tips == 'no':
-
break
-
-
#發版,上傳jar包到生產伺服器
-
while True:
-
temp = str(raw_input('9)請問開始向生產伺服器發版嗎?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin publish..."
-
dirs = [item for item in os.listdir('patch/') if not item.endswith('zip')]
-
for index,item in enumerate(dirs,1):
-
if item == 'bj-oms-api':
-
print "%d: %s is publishing..." % (index,item)
-
output = subprocess.check_output(['fab','put_bj_oms_api_jar_4748_3746_4041'],shell=True,stderr = subprocess.STDOUT) #shell=True在windows時可以關閉cmd視窗的回顯
-
print output
-
output = subprocess.check_output(['fab','put_bj_oms_api_jar_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
print
-
elif item == 'bj-oms-domain':
-
print "%d: %s is publishing..." % (index,item)
-
output = subprocess.check_output(['fab','put_bj_oms_domain_jar_4748_3746_4041'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','put_bj_oms_domain_jar_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-core-new1':
-
print "%d: %s is publishing..." % (index,item)
-
output = subprocess.check_output(['fab','put_bj_oms_core_new1_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-rest':
-
print "%d: %s is publishing..." % (index,item)
-
output = subprocess.check_output(['fab','put_bj_oms_rest_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-jobs':
-
print "%d: %s is publishing..." % (index,item)
-
output = subprocess.check_output(['fab','put_bj_oms_job_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-web':
-
print "%d: %s is publishing..." % (index,item)
-
output = subprocess.check_output(['fab','put_bj_web'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif item == 'bj-oms-core':
-
print "%d: %s is publishing..." % (index,item)
-
output = subprocess.check_output(['fab','put_bj_oms_core_jar'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
break
-
elif tips == 'no':
-
break
-
-
#關閉服務
-
while True:
-
temp = str(raw_input('10)請問開始關閉服務嗎,包含服務tomcat、rest、job、core?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin stop service..."
-
output = subprocess.check_output(['fab','stop_cz_tomcat_oms_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','stop_cz_bj_oms_rest_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','stop_cz_bj_oms_job_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','stop_cz_oms_core_4748'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','stop_cz_oms_core__new_3746'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','stop_cz_oms_core__new1_4041'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
-
elif tips == 'no':
-
break
-
-
#開啟服務
-
while True:
-
temp = str(raw_input('11)請問開始啟動服務嗎,包含服務core、tomcat、rest、job?[yes/no]:'.decode('utf-8').encode('gb2312')))
-
tips = temp.strip().lower()
-
if tips == 'yes':
-
print "Now begin stop service..."
-
output = subprocess.check_output(['fab','start_cz_oms_core__new1_4041'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','start_cz_oms_core__new_3746'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','start_cz_oms_core_4748'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','start_cz_tomcat_oms_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','start_cz_bj_oms_rest_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
output = subprocess.check_output(['fab','start_cz_bj_oms_job_30'],shell=True,stderr = subprocess.STDOUT)
-
print output
-
elif tips == 'no':
- break
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28916011/viewspace-2153243/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- nginx自己寫日誌切割指令碼Nginx指令碼
- 自己寫的殺mysql執行緒的指令碼MySql執行緒指令碼
- 編寫自己的Acunetix WVS漏洞指令碼指令碼
- DBA日常維護SQL指令碼_自己編寫的SQL指令碼
- 介紹一個自己寫的crs_stat指令碼指令碼
- 如何看待自己寫的爛程式碼
- 用自己寫的awk指令碼及Oracle包成功恢復客戶的重要資料!指令碼Oracle
- 自己寫的部分實用的程式碼
- gdb指令碼編寫指令碼
- Shell 指令碼編寫指令碼
- shell 指令碼寫法:指令碼
- Fabric 1.0原始碼分析(44)Tx #RWSet(讀寫集)原始碼
- 自己寫的油猴指令碼 —— 貝殼網自動計算實際使用面積指令碼
- 編寫shell指令碼的規範指令碼
- 如何編寫高效的 Shell 指令碼指令碼
- 寫出健壯的Bash指令碼指令碼
- 油猴指令碼編寫指令碼
- 編寫git指令碼.shGit指令碼
- 自己寫的unix檔案拷貝指令cp實現函式函式
- 編譯FFMPEG原始碼的指令碼編寫案例編譯原始碼指令碼
- 專案啟動指令碼的編寫指令碼
- Ollydbg 編寫指令碼的一些語法及例子(OD指令碼)指令碼
- RAC 節點2刪除自己的歸檔指令碼指令碼
- 如何用 ANTLR 4 實現自己的指令碼語言?指令碼
- shell指令碼之if elif寫法指令碼
- EA指令碼編寫要點指令碼
- 編寫執行R指令碼指令碼
- shell指令碼寫氣泡排序指令碼排序
- 自己寫的面試題,自己想的答案面試題
- nGrinder中快速編寫groovy指令碼01-指令碼結構指令碼
- awk命令和指令碼的編寫啟蒙指令碼
- 如何寫出安全又可靠的PHP指令碼PHP指令碼
- 寫好shell指令碼的8個建議指令碼
- 如何編寫冪等的 Bash 指令碼?- Arslan指令碼
- [轉]寫好shell指令碼的13個技巧指令碼
- 寫最少的程式碼,避免給自己找麻煩
- 寫最少的程式碼 避免給自己找麻煩
- 從零開始 實現一個自己的指令碼引擎指令碼