Every Tomcat project in the company now has two environments for testing and production, and it is time-consuming and labor-intensive for tomcat projects that often need to be on-line, such as manual updates. The current fabric has developed a script that automatically publishes the Tomcat project, which has been used very stably in the company.
The fabric Auto Release script process is as follows:
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/82/0B/wKioL1dJDgvA_B50AABODyhi-8s962.png "title=" QQ picture 20160528105201.png "alt=" Wkiol1djdgva_b50aabodyhi-8s962.png "/>
The Fabric auto-publish script is as follows:
#!/usr/bin/python#coding=utf-8from fabric.api import *from fabric.colors import *from fabric.context_managers import *from fabric.contrib.console import confirmenv.user= ' root ' env.hosts=[' 192.168.1.10 ']env.password= ' 123456789 ' env.svn_user= ' userabd ' Env.svn_password = ' 123456 ' env.svn_url= ' svn://192.168.1.20/source/java/project ' env.svn_local_path= '/data/svn/' env.remote_path= '/ data/company/project/' @taskdef package_project (): print yellow (' Start package file ')     WITH LCD (Env.svn_local_path): Local ("svn co %s --username=%s --password=%s" % (env.svn_url,env.svn_user,env.svn_ Password))         WITH LCD ("%s ' Project '" % (Env.svn_local_ Path): local ("mvn clean Package -dmaven.test.skip=true&nBsp;-ptest -u ") with lcd ("%s " Project/target ' " % (Env.svn_local_path)): result=local (' ls |grep project.*war$ ', capture=True) print Yellow (' Package file Success ') print yellow (' Packaged file:%s ' % (result)) @taskdef put_package (): Print yellow (' Start uploading file ') with lcd ("%s ' Project/target '" % (Env.svn_local_ Path): result=local (' ls |grep project.*war$ ', capture =true) env.local_war_path=env.svn_local_path + ' project/target/' + Result &nbsP;WITH CD ("Env.remote_path"): put (Env.local_war_path, Env.remote_path) @taskdef check_task ():  WITH LCD ("%s ' Project/target '" % (Env.svn_local_path)): result=local (' ls |grep project.*war$ ', capture=true) env.local_war_path=env.svn_local_path + ' project/target/' + result env.remote_war_path=env.remote_path + result lmd5=local ("md5sum %s" % (Env.local_war_path),capture=True ). Split (' ') [0] rmd5=run ("md5sum %s" % (Env.remote_war_path)). Split (' ') [0] if lmd5 == rmd5: &Nbsp; print green (' Upload file Success ') else: print red (' Upload file failed ') @taskdef unpack_project (): print yellow (' Start decompression War package ')     WITH LCD ("%s ' Project/target '" % (Env.svn_local_path)): result=local (' ls |grep project.*war$ ', capture=true)         WITH CD (Env.remote_path): run ("Find . ! -name ' *war ' -a ! -name .| Xargs rm -rf ") run (" Unzip %s " % (Result)") @taskdef switch_production (): print yellow (' Start switch production Environment profile ')  WITH CD (Env.remote_path): run (' sed -i s/ Test/production/g web-inf/classes/applicationcontext.xml ') @taskdef restart_tomcat (): print yellow (' Restart Tomcat process ') run ('/usr/local/tomcat/bin/shutdown.sh ') run (' sleep 10 ') run ('/usr/local/tomcat/bin/startup.sh ') @ Taskdef production (): package_project () put_package () check_task () unpack_project () switch_ Production () restart_tomcat ()
How to use the script: fab-f name.py production
This article is from "My In Lushan" blog, please be sure to keep this source http://147546.blog.51cto.com/137546/1784002
Fabric automatically publishes Tomcat line items