博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Shell脚本-自动化部署WEB
阅读量:5332 次
发布时间:2019-06-14

本文共 3591 字,大约阅读时间需要 11 分钟。

一、打包项目

1、从git克隆代码到本地

2、项目源码存储在/data/path/project_name目录下,eg:/data/back-end/peach
3、通过maven命令将jar/war安装到本地仓库
4、脚本文件取名为:install.sh

#! /bin/bashif [ $# -ne 3 ]  then      echo "#### 参数有误,\$1:相对路径,\$2:项目名,\$3:分支版本"    echo "#### 输入参数格式如:"    echo "#### back-end peach master"    echo "#### back-end pear v2.0"    exit 1  fi  echo "#### 输入参数,\$1:$1,\$2:$2,\$3:$3"project_path=/data/$1/$2echo "#### $2项目源码存储路径:"$project_pathrm -rf $project_pathecho "#### $2项目源码删除完毕"git_path="git@gitlab.xm6f.com:"$1/$2".git"echo '#### git克隆代码 from '$git_path' to '$project_pathgit clone $git_path $project_pathecho '#### git克隆代码完毕.....'branchName=$2_$3if [ "$3" == "master" ]then    branchName="master"ficd $project_pathgit checkout $branchNamegit pullmvn clean installecho "#### $2项目打包完毕....."

 二、部署项目

#! /bin/bashif [ $# -ne 4 ]then    echo "#### 参数有误,\$1:项目名,\$2:tomcat路径,\$3:ip地址, \$4:war path"exit 1fiscp $4 root@$3:$2"/temp/"ssh root@$3  << eeooff        cd $2        #####查找tomcat进程并杀死        ps -ef | grep '$2' | grep -v grep | awk '{print \$2}' | xargs kill -9            mv "webapps/"$1".war" "temp/"$1"_"$(date +%Y%m%d%H%M%S)".war"        mv "temp/"$1".war" webapps/        rm -rf webapps/$1        rm -rf webapps/ROOT* $1        rm -rf work/        rm -rf temp/$1".war"        bin/startup.sh &        exiteeooff

 

三、自动化部署web项目

1、脚本文件取名为:startup.sh

2、执行命名:./startup.sh pear master

#! /bin/bashif [ $# -ne 2 ]  then      echo "#### 参数有误,\$1:项目名,\$2:分支版本"    echo "#### 输入参数格式如:peach master | pear v2.0 | pear v2.0_dzy"   exit 1  fiwar_path="/data/back-end/$1/target/$1.war"remote_tomcat=/home/xm6f/dev/sh install.sh back-end monkey $2if [ "$1" == "peach" ] then    sh install.sh back-end banana $2    sh install.sh back-end $1 $2    remote_tomcat=$remote_tomcat"tomcat8088"    remote_ip=192.168.1.160        sh deploy.sh $1 $remote_tomcat $remote_ip $war_pathelif [ "$1" == "mango" ] then    sh install.sh back-end banana $2    sh install.sh back-end $1 $2    remote_tomcat=$remote_tomcat"tomcat-8081"    remote_ip=192.168.1.35    sh deploy.sh $1 $remote_tomcat $remote_ip $war_path elif [ "$1" == "pear" ] then    sh install.sh back-end banana $2    sh install.sh back-end $1 $2    remote_tomcat=$remote_tomcat"tomcat-7.0.79/tomcat-8080"    remote_ip=192.168.1.105    sh deploy.sh $1 $remote_tomcat $remote_ip $war_path  elif [ "$1" == "apple" ] then    sh install.sh back-end banana $2    sh install.sh back-end $1 $2    remote_tomcat=$remote_tomcat"tomcat-7.0.79/tomcat-8082"    remote_ip=192.168.1.105    sh deploy.sh $1 $remote_tomcat $remote_ip $war_path  elif [ "$1" == "tomato" ] then    sh install.sh back-end banana $2    sh install.sh back-end $1 $2    remote_tomcat=$remote_tomcat"tomcat-7.0.79/tomcat-8081"    remote_ip=192.168.1.105    sh deploy.sh $1 $remote_tomcat $remote_ip $war_path  elif [ "$1" == "pig" ] then    sh install.sh back-end tiger $2    sh install.sh back-end $1 $2    remote_tomcat=$remote_tomcat"tomcat8081"    remote_ip=192.168.1.160    sh deploy.sh $1 $remote_tomcat $remote_ip $war_path elif [ "$1" == "deer" ] then    sh install.sh back-end tiger $2    sh install.sh back-end $1 $2    remote_tomcat=$remote_tomcat"tomcat-8083"    remote_ip=192.168.1.160    sh deploy.sh $1 $remote_tomcat $remote_ip $war_pathelif [ "$1" == "lotmall" ]then    sh install.sh back-end $1 $2    remote_tomcat="/www/server/tomcat"    remote_ip=192.168.1.35    sh deploy.sh $1 $remote_tomcat $remote_ip $war_pathelif [ "$1" == "order" ] then    sh install.sh back-end tiger $2    sh install.sh back-end $1 $2else    echo "####没有找到匹配的项目名"fi

 

转载于:https://www.cnblogs.com/linjiqin/p/7779341.html

你可能感兴趣的文章
stm32中字节对齐问题(__align(n),__packed用法)
查看>>
like tp
查看>>
posix多线程有感--线程高级编程(线程属性函数总结)(代码)
查看>>
spring-使用MyEcilpse创建demo
查看>>
DCDC(4.5V to 23V -3.3V)
查看>>
kettle导数到user_用于left join_20160928
查看>>
activity 保存数据
查看>>
typescript深copy和浅copy
查看>>
linux下的静态库与动态库详解
查看>>
hbuilder调底层运用,多张图片上传
查看>>
较快的maven的settings.xml文件
查看>>
Git之初体验 持续更新
查看>>
随手练——HDU 5015 矩阵快速幂
查看>>
Maven之setting.xml配置文件详解
查看>>
SDK目录结构
查看>>
malloc() & free()
查看>>
HDU 2063 过山车
查看>>
高精度1--加法
查看>>
String比较
查看>>
Django之Models
查看>>