#!/usr/bin/python
from fabric.api import *
from fabric.context_managers import *
from fabric.contrib.console import confirm
from fabric.contrib.files import *
import time,os
i='machtalk@10.112.80.2:22'
env.hosts=[i]
env.roledefs = {
'all':[i]
}
env.passwords = {
i:'GVk2qWUTW7kP2hwQ'
}
env.profile='300'
env.project_basepath='/opt/svncode/gitpro/'
env.project_parent_dir = env.project_basepath+'xcloud-parent-gome/'
env.postfix='-1.0.war'
env.deploy_basepath='/opt/machtalk/pro/'
def project_update(dir_path):
with lcd(dir_path):
local("/usr/bin/git fetch origin")
local("/usr/bin/git checkout feature/gome-bussiness-manager")
#local("/usr/bin/git pull origin feature/gome-bussiness-manager")
def project_package(dir_path, project_name):
with lcd(dir_path):
local("/usr/local/maven3/bin/mvn clean package -Dmaven.test.skip=true -P "+env.profile+","+project_name)
def project_init_dir():
if not exists(env.deploy_basepath):
run("mkdir -p "+env.deploy_basepath+"logs")
if not exists("/data/logs"):
run("sudo mkdir -p /data")
run("sudo ln -s "+(env.deploy_basepath+"logs")+" /data/logs")
def project_put(source_dir, target_dir):
result = put(source_dir, target_dir)
if result.failed and not confirm("put file failed, Continue[Y/NO]?"):
abort("aborting!")
def project_port_stop(port):
with settings(warn_only=True):
result = run("sudo netstat -lnp|grep "+port+"|awk '{print $7}'|awk -F '/' '{print $1}'")
if result:
run("kill "+result)
def project_clean(webapp_dir):
run('rm -rf '+webapp_dir+'*')
def project_start(deploy_dir):
with settings(warn_only=True):
with cd(deploy_dir + "bin"):
run("set -m; ./startup.sh")
def project_deploy(project_dir,project_name, port):
deploy_dir = env.deploy_basepath + project_name + '/' + project_dir + '/'
webapp_dir = deploy_dir + "webapps/"
war_name = project_name + env.postfix
project_init_dir()
project_update(env.project_parent_dir)
project_package(env.project_parent_dir, project_name)
project_port_stop(port)
project_clean(webapp_dir)
project_put(env.project_parent_dir+project_name+'/target/'+war_name, webapp_dir+'ROOT.war')
project_start(deploy_dir)
@task
@roles('all')
def bm():
project_deploy('bm-tomcat8','xcloud-bussiness-manager-gome','10055')
----------------------------------------------------------------
#!/usr/bin/python
from fabric.api import *
from fabric.context_managers import *
from fabric.contrib.console import confirm
from fabric.contrib.files import *
import time,os
i='machtalk@10.112.80.2:22'
env.hosts=[i]
env.roledefs = {
'all':[i]
}
env.passwords = {
i:'GVk2qWUTW7kP2hwQ'
}
env.profile='qa'
env.project_basepath='/opt/svncode/gitpro/'
env.project_parent_dir = env.project_basepath+'gome-server/'
env.deploy_basepath='/opt/machtalk/pro/'
def project_update(dir_path):
with lcd(dir_path):
local("git fetch origin")
local("git checkout develop")
local("git pull")
def project_package(dir_path, project_name):
with lcd(dir_path):
local("/usr/local/maven3/bin/mvn clean package -Dmaven.test.skip=true -P "+env.profile+","+project_name)
def project_init_dir(deploy_path):
if not exists(env.deploy_basepath):
run("mkdir -p "+env.deploy_basepath+"logs")
if not exists("/data/logs"):
run("sudo mkdir -p /data")
run("sudo ln -s "+(env.deploy_basepath+"logs")+" /data/logs")
if not exists(deploy_path):
run("mkdir -p "+deploy_path)
def project_put(source_dir, target_dir):
result = put(source_dir, target_dir)
if result.failed and not confirm("put file failed, Continue[Y/NO]?"):
abort("aborting!")
def project_port_stop(port):
with settings(warn_only=True):
result = run("sudo netstat -lnp|grep "+port+"|awk '{print $7}'|awk -F '/' '{print $1}'")
if result:
run("sudo kill "+result)
def project_clean(deploy_dir):
run('rm -rf '+deploy_dir+'/*')
def project_module_gz(project_dir):
with lcd(project_dir):
local("tar -czf product.tar.gz ./*" )
def project_cmd_stop(cmd):
with settings(warn_only=True):
run("sudo ps aux|grep "+cmd+"|grep -v grep | awk '{print $2}' |xargs -i kill -9 {}")
def project_module_ungz(deploy_dir, tarname):
with cd(deploy_dir):
run("tar -xzf "+tarname)
run("rm -rf "+tarname)
def project_start(deploy_dir):
with settings(warn_only=True):
with cd(deploy_dir+"bin/"):
run("chmod 755 start.sh tail.sh")
run("set -m; ./start.sh start")
def project_deploy(project_name, port):
deploy_dir = env.deploy_basepath + project_name+'/'
project_init_dir(deploy_dir)
project_update(env.project_parent_dir)
project_package(env.project_parent_dir, project_name)
project_port_stop(port)
project_clean(deploy_dir)
project_module_gz(env.project_parent_dir+project_name+"/product")
project_put(env.project_parent_dir+project_name+"/product/product.tar.gz", deploy_dir)
project_module_ungz(deploy_dir, "product.tar.gz")
project_start(deploy_dir)
def mq_deploy(project_name, cmd):
deploy_dir = env.deploy_basepath + project_name+'/'
project_init_dir(deploy_dir)
project_update(env.project_parent_dir)
project_package(env.project_parent_dir, project_name)
project_cmd_stop(cmd)
project_clean(deploy_dir)
project_module_gz(env.project_parent_dir+project_name+"/product")
project_put(env.project_parent_dir+project_name+"/product/product.tar.gz", deploy_dir)
project_module_ungz(deploy_dir, "product.tar.gz")
project_start(deploy_dir)
@task
@roles('all')
def dispatcher():
project_deploy('xcloud-dispatcher', '6770')
@task
@roles('all')
def ds():
project_deploy('xcloud-ds', '7778')
@task
@roles('all')
def ncs():
project_deploy('xcloud-ncs', '2348')
@task
@roles('all')
def nls():
project_deploy('xcloud-nls', '7779')
@task
@roles('all')
def mq():
mq_deploy('xcloud-mq-gome', 'MQRun')
----------------------------------------------------------------------------------------------
#!/usr/bin/python
from fabric.api import *
from fabric.context_managers import *
from fabric.contrib.console import confirm
from fabric.contrib.files import *
import time,os
i='machtalk@10.112.80.2:22'
env.hosts=[i]
env.roledefs = {
'all':[i]
}
env.passwords = {
i:'GVk2qWUTW7kP2hwQ'
}
env.profile='qa'
env.project_basepath='/opt/svncode/gitpro/'
env.project_parent_dir = env.project_basepath+'next-parent/'
env.postfix='-1.0-SNAPSHOT-exec.jar'
env.deploy_basepath='/opt/machtalk/pro/'
env.exec_dir_name = 'exec'
def project_update(dir_path):
with lcd(dir_path):
local("/usr/bin/git fetch origin")
#local("/usr/bin/git checkout houfuwu")
local("/usr/bin/git checkout 200")
#local("/usr/bin/git pull origin houfuwu")
local("/usr/bin/git pull origin 200")
def project_package(dir_path, project_name):
with lcd(dir_path):
local("/usr/local/maven3/bin/mvn clean package -Dmaven.test.skip=true -P "+env.profile+","+project_name)
def project_init_dir(deploy_path):
if not exists(env.deploy_basepath):
run("mkdir -p "+env.deploy_basepath+"logs")
if not exists("/data/logs"):
run("sudo mkdir -p /data")
run("sudo ln -s "+(env.deploy_basepath+"logs")+" /data/logs")
if not exists(deploy_path):
run("mkdir -p "+deploy_path+env.exec_dir_name)
run("mkdir -p "+deploy_path+"bak")
def project_put(source_dir, target_dir):
result = put(source_dir, target_dir)
if result.failed and not confirm("put file failed, Continue[Y/NO]?"):
abort("aborting!")
def project_port_stop(port):
with settings(warn_only=True):
result = run("sudo netstat -lnp|grep "+port+"|awk '{print $7}'|awk -F '/' '{print $1}'")
if result:
run("kill -9 "+result)
def project_clean(project_name,exec_dir):
# run('cp * ../bak/'+'`date +%y%m%d%s`'+project_name+'1.0-SNAPSHOT-exec.jar')
run('rm -rf '+exec_dir+'/*')
def project_start(exec_dir, jar_name):
with settings(warn_only=True):
with cd(exec_dir):
run("set -m; nohup java -server -Xms512m -Xmx1024m -Xss512k -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m -jar "+jar_name+" >/dev/null 2>&1 &")
def project_deploy(project_name, port):
deploy_dir = env.deploy_basepath + project_name+'/'
exec_dir = deploy_dir + env.exec_dir_name
jar_name = project_name + env.postfix
project_init_dir(deploy_dir)
project_update(env.project_parent_dir)
project_package(env.project_parent_dir, project_name)
project_port_stop(port)
project_clean(project_name,exec_dir)
project_put(env.project_parent_dir+project_name+'/target/'+jar_name, exec_dir+'')
project_start(exec_dir, jar_name)
@task
@roles('all')
def commonservice():
project_deploy('xcloud-commonservice', '2003')
阅读(1953) | 评论(0) | 转发(0) |