Shell从git拉取代码并编译部署到tomcat

Shell从git拉取代码并编译部署到tomcat

目录结构

/data 根目录
/data/deploy shell脚本目录
/data/git-code git上拉取代码的目录
/data/tools tomcat目录
/data/webapps war包目录

shell脚本

#!/bin/bash

tomcat_name="tomcat-web-hello"
# git/项目名称
git_name="web"
# 模块名称
module_name="web-hello"

#停止tomcat
function killTomcat(){
  ps -ef | grep $tomcat_name | grep -v 'grep' | awk '{print $2}' | xargs kill -9
  echo "killd tomcat "
}

function startTomcat(){
  ps -ef | grep $tomcat_name | grep -v 'grep' | awk '{print $2}' | xargs kill -9
  cd /data/tools/$tomcat_name/bin/
  nohup ./startup.sh
  echo "start tomcat end"
  tail -f /data/tools/$tomcat_name/logs/catalina.out
}

function svnmvn(){
  cd /data/git-code/$git_name
  git fetch
  if [ "$branch" != "" ]
  then
  git checkout -b $branch origin/$branch
  git checkout $branch
  fi
  git pull
  mvn clean install -Dmaven.test.skip=true
}

function deployWar(){
  dir=`date +%Y%m%d-%H%M`
  cd /data/webapps/$module_name
  rm * -rf

  cp /data/git-code/$git_name/$module_name/target/$module_name-1.0-SNAPSHOT.war /data/webapps/$module_name
  unzip $module_name-1.0-SNAPSHOT.war
}


echo -n "!!!$git_name-输入部署的分支: "
read branch

svnmvn $branch
if [ $? -eq 0 ]
then
  deployWar
  killTomcat
  sleep 2
  startTomcat
else
  echo "ERROR: mvn failed!"
fi

其他设置

进入tools目录下对应的tomcat

cd /data/tools/tomcat-web-hello/conf

设置启动参数

vim catalina.properties

最后一行添加

spring.profiles.active=prod

设置缓存

避免缓存不足报错

vim content.xml

添加位于

<Context>
    
    
    <WatchedResource>WEB-INF/web.xmlWatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xmlWatchedResource>

    
    
    <Resources cachingAllowed="true" cacheMaxSize="100000" />
Context>

设置tomcat部署路径

注:如果不设置,shell脚本中的webapps应改为 tomcat下的webapps路径

vim server.xml

添加位于

<Host name="localhost"  appBase="webapps" 
	unpackWARs="true" autoDeploy="true">

    
    

    
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
    prefix="localhost_access_log" suffix=".txt"
    pattern="%h %l %u %t "%r" %s %b" />
    <Context path="/" docBase="/data/webapps/web-hello" debug="0"/>
Host>

你可能感兴趣的:(tomcat,java)