Description
The script implementation remotely sends the local project project package to the remote server. And the old version of the project back up, upload the new project, the project in the script automatically the startup script of the project itself.
#!/usr/bin/env python#coding:utf-8#author summer#create date:2015-07-29import Datetimeimport timefrom fabric.context_managers import *from fabric.contrib.console import confirmfrom fabric.colors import *from fabric.api import * #本地开发服务器信息env. local_package_dir= '/web ' Env.time=time.strftime ("%y%m%d") env.local_bakcup_dir= '/tmp ' Env.local_package_name= ' target ' #远程服务器信息env. hosts=[' 223.203.219.133 ', ' 223.203.219.134 ', ' 223.203.219.135 '] env.port= ' 3217 ' env.user= ' root ' env.password= ' [email protected]# $xuniSHIJIE 2707 ' env.remote_package_dir= '/ Web ' #备份函数 @task @runs_oncedef backup_task (): print yellow ("<---------- ----Start backing up the new Package-------------->) with lcd ("%s" %env.local_package_dir): local ("tar zcvf %s-%s.tar.gz %s" % ( Env.local_package_name,env.time,env.locaL_package_name) print blue ("<------------new Package backup creation successful------------->") #上传函数 @taskdef put_task (): print yellow (<-------------start stop service--------->) run ('%s/%s/apiserver stop ' % (env.local_package_dir,env.local_package_name)) print blue ("<-------------stop service success--------->") print yellow ("<-- -----------Delete old package------------> ") run (' rm -fr %s/%s* ' % (env.remote _package_dir,env.local_package_name) print blue ("<-----------old package deleted successfully---- ----> ") print yellow (" <-----------start uploading new packages--- --- ) #run ("mkdir %s" %env.remote_package_dir) with lcd ("%s" %env.local_package_dir): put ('%s-%s.tar.gz ' % (env.local_ Package_name,env.time), '%s/%s-%s.tar.gz ' % (env.local_package_dir,env.local_package_name,env.time)) print blue (' <-----------new package uploads successfully----------> ') run (' Tar zxf %s/%s-%s.tar.gz -c %s ' % (Env.local_package_dir,env.local_package_name,env.time, Env.local_package_dir) print blue (' <-------------extract success------------> ') with cd ('%s/%s ' % (env.remote_package_dir,env.local_package_name) ): run ('./apiserver start ') print blue (' <-------Apiserver service runs successfully-------> ') @taskdef start (): backup_task () Put_task ()
This article from the "Do not ask for the best, only better" blog, please be sure to keep this source http://yujianglei.blog.51cto.com/7215578/1725597
Python script for Project Engineering automatic remote deployment