Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use fabric to automate distribution

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use fabric to automate distribution. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Function: automatic distribution using 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'

}

# Universal function

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 ()

# generate the distribution directory according to filelist

Def faban_dir ():

Count = 0

With open ('filelist.txt','r') as f:

For line in f:

If line.startswith ('bj-oms-api'):

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-oms-api/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-oms-api/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-oms/bj-oms-api/target/classes/','patch/bj-oms-api/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Elif line.startswith ('bj-oms-domain'):

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-oms-domain/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-oms-domain/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-oms/bj-oms-domain/target/classes/','patch/bj-oms-domain/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Elif line.startswith ('bj-oms-core-new1'): # location 1, which is not interchangeable because bj-oms-core contains bj-oms-core-new1

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-oms-core-new1/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-oms-core-new1/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-oms/bj-oms-core-new1/target/classes/','patch/bj-oms-core-new1/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Elif line.startswith ('bj-oms-core'): # location 2, which is not interchangeable because bj-oms-core contains bj-oms-core-new1

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-oms-core/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-oms-core/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-oms/bj-oms-core/target/classes/','patch/bj-oms-core/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Elif line.startswith ('bj-oms-rest'):

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-oms-rest/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-oms-rest/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-oms/bj-oms-rest/target/classes/','patch/bj-oms-rest/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Elif line.startswith ('bj-oms-jobs'):

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-oms-jobs/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-oms-jobs/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-oms/bj-oms-jobs/target/classes/','patch/bj-oms-jobs/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Elif line.startswith ('bj-tran'):

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-tran/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-tran/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-tran/target/classes/','patch/bj-tran/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Elif line.startswith ('bj-whm-rest'):

# filelist file path preprocessing

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 ('\ nnewline character removed) #

# construct patch directory structure

Patchpath_filename = line.replace ('bj-whm-rest/src/main/java/','')

Patchpath_filename = patchpath_filename.replace ('.java', '.class')

Patchpath_filename = patchpath_filename.replace ('\ nFengzhongjinshou')

Patchpath_filename = 'patch/' +' bj-whm-rest/' + patchpath_filename

Patchpath = os.path.dirname (patchpath_filename)

# if the patch directory does not exist, set up a directory

Try:

Os.listdir (patchpath)

Except WindowsError:

Os.makedirs (patchpath) # makedirs can recursively create a folder under the patch directory of windows

# copy the parent class to the patch directory

Parentclass_path_filename = classpath_filename

Patchpath_filename = patchpath_filename

Print "copy the svn class file to the patch directory:% s->% s"% (parentclass_path_filename,patchpath_filename)

Shutil.copy (parentclass_path_filename,patchpath_filename)

Count + = 1

Print "*% s file copy succeeded *"% count

# use glob to find subclasses

Path_filename = os.path.split (classpath_filename) # split: returns a tuple containing the path and file name of the file

Filename_splitext = os.path.splitext (path_filename [1]) # remove the file extension

Subclass_path_filenames = glob.glob ('% sram% swatches'% (path_filename [0], filename_ plitext [0]))

# copy the subclasses to the patch directory

For subclass_path_filename in subclass_path_filenames:

Subclass_path_filename = subclass_path_filename.replace ('\\', rattlespace')

Patchpath_filename = subclass_path_filename.replace ('.. / online_svn/bj-whm-rest/target/classes/','patch/bj-whm-rest/')

Print "copy the svn subclass file to the patch directory:% s->% s"% (subclass_path_filename,patchpath_filename)

Shutil.copy (subclass_path_filename,patchpath_filename)

Count + = 1

Print "* the% s file was copied successfully. Note that the file is a subclass ^ _ ^ *"% count

Else:

Print's: the project is not configured, please contact the administrator "% line"

Sys.exit ()

# down jar package

@ 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/')

# replace the files in the jar package

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 package backup to / backup directory of 10.2.88.47')

@ 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 package backup to / backup directory of 10.2.88.47')

@ 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 package backup to / backup directory of 10.2.88.40')

@ 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 package backup to / backup/ directory of 10.2.88.30')

@ 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 package backup to / backup/ directory of 10.2.88.30')

@ 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 package backup to / backup/ directory of 10.2.88.30')

@ 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 package backed up to / backup/ directory of 10.2.88.30')

# release version, upload jar package

@ 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')

# restart the service

@ 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)

# main program

If _ _ name__ = ='_ _ main__':

# Update SVN

While True:

Temp = str (raw_input ('1) do you want 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

# Delete everything in the patch directory

While True:

Temp = str (raw_input ('2) delete all directories under the patch directory? [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

# prompt whether to compile the code with eclipse

While True:

Temp = str (raw_input ('3) hint: did you manually compile the css code through eclse [yes/no]:')

Tips = temp.strip () .lower ()

If tips = 'yes':

Break

Elif tips = 'no':

Break

# generate the distribution directory according to filelist

While True:

Temp = str (raw_input ('4) generates a distribution directory based on 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) decompress the zip package to the local patch directory? [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) download the jar package to the local patch directory? [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 can turn off the echo of the cmd window during windows

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 download failed because the file is not configured in the distributor, please contact the administrator')% item

Sys.exit ()

Break

Elif tips = 'no':

Break

# replace file to jar

While True:

Temp = str (does raw_input ('7) replace the configuration file in the jar package? [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 ('Note: because there are duplicate files in the bj-oms-core-new1 package, you need to update the contents of the jar package manually. Have you updated it? [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 (does raw_input ('8) want to back up the jar package of the remote server before the official release? [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 can turn off the echo of the cmd window during windows

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

# release version, upload the jar package to the production server

While True:

Temp = str (raw_input ('9) will you start sending the version to the production server? [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 can turn off the echo of the cmd window during windows

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

# disable the service

While True:

Temp = str (raw_input ('10) would you like to start shutting down services, including services 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

# enable the service

While True:

Temp = str (raw_input ('11) would you like to start the service, including services 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

Thank you for reading! This is the end of this article on "how to use fabric Automation Edition". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report