Python script for Project Engineering automatic remote deployment

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.