部署Test Java 环境[2.0]

#!/bin/bash

# 部署Test Java 环境
#Author: Jasonote
#Date  : 2017/11/09
#version: 2.0.0
#
source /etc/profile
###  auto-order  new-srm  pms-product  smart-alarm  ###

while :; do echo
  echo "Please choose to use project:"
  echo -e "\t 1 . Use auto-order"
  echo -e "\t 2 . Use new-srm"
  echo -e "\t 3 . Use pms-product"
  echo -e "\t 4 . Use smart-alarm"
  echo -e "\t 5 . Use new-allocation"
  echo -e "\t 6 . Use procurement-order"
  echo -e "\t 7 . Use supplier-app-api"
  read -p "Please input a number:(Default 1 press Enter) " Choose_number
  [ -z "${Choose_number}" ] && Choose_number=1
  if [[ ! ${Choose_number} =~ ^[1-7]$ ]]; then
    echo "input error! Please only input number 1,2,3,4,5,6,7"
  else
    break
  fi
done
case "${Choose_number}" in
  1)
    project=auto-order
    ;;
  2)
    project=new-srm
    ;;
  3)
    project=pms-product
    ;;
  4)
    project=smart-alarm
    ;;
  5)
    project=new-allocation
    ;;
  6)
    project=procurement-order
    ;;
  7)
    project=supplier-app-api
    ;;

esac

###确定部署的版本号
read -p "Please input project version : " version

###决定是否同一个服务器上都起
while :; do echo
  echo "Please choose to deploy type:"
  echo -e "\t 1 . Use all"
  echo -e "\t 2 . Use main"
  echo -e "\t 3 . Use web"
  echo -e "\t 4 . Use gateway"
  echo -e "\t 5 . Use web,gateway"
  read -p "Please input a number:(Default 1 press Enter) " deploy_type
  [ -z "${deploy_type}" ] && deploy_type=1
  if [[ ! ${deploy_type} =~ ^[1-5]$ ]]; then
    echo "input error! Please only input number 1,2,3,4,5"
  else
    break
  fi
done
case "${deploy_type}" in
  1)
    deploy=all
    ;;
  2)
    deploy=main
    ;;
  3)
    deploy=web
    ;;
  4)
    deploy=gateway
    ;;
  5)
    deploy=webgateway
    ;;
esac

#/data/java/source
#/Volumes/work
################代码目录################
dr="/data/java/source"
service="/data/service"
################代码目录################

code=$dr/$project

echo "当前项目目录" : $code
cd $code;

sudo git fetch origin
sudo git branch
printf "Enter branch:"
read branch
if [ ! -n "$branch" ]
then
   sudo git pull origin
else
   sudo git stash && git fetch
   sudo git checkout $branch
   sudo git pull origin $branch
   sudo git stash pop
fi
sudo git branch

echo 'who:' `whoami` 'project:'$project 'gitBranch:' $branch  'Date:'`date +"%Y-%m-%d %H:%M:%S"` >> /data/Jasonote/xx/JavaDeploy.log


#mvn 打包
mvnp=`which mvn`
sudo $mvnp clean package -Dmaven.test.skip=true -Ptest

point=`ps -ef | grep $project | awk '{print $2}'`
for i in $point; do
    echo "关闭当前端口:"$i
    sudo kill -9 $i
done

#起Main程序
key=$project

###确认版本
if  [  -n "$version" ] ;then
     if [[ $project == "new-srm" ]]; then
        key="supplier"
        main_=$code/$key-main/target/$key-main-$version/$key-main-$version/bin
      else
        main_=$code/$key-main/target/$key-main-$version/$key-main-$version/bin
    fi
else
    if [[ $project == "new-srm" ]]; then
        key="supplier"
        main_=$code/$key-main/target/$key-main-1.0.9/$key-main-1.0.9/bin
    elif [[ $project == "pms-product" ]]; then
        main_=$code/$key-main/target/$key-main-1.0.2/$key-main-1.0.2/bin
    elif [[ $project == "procurement-order" ]]; then
        main_=$code/$key-main/target/$key-main-1.0.7/$key-main-1.0.7/bin
    elif [[ $project == "supplier-app-api" ]]; then
        main_=$code/$key-main/target/$key-main/$key-main-1.0.7/bin
    else
        main_=$code/$key-main/target/$key-main-1.0-SNAPSHOT/$key-main-1.0-SNAPSHOT/bin
    fi
fi



echo key--------$key----------key

echo "=========================启动服务==============================="

#初始化环境
export JAVA_HOME=/usr/local/java/jdk1.8.0_111
export JRE_HOME=$JAVA_HOME/jre
export CATALINA_HOME=/usr/local/java/apache-tomcat-8.0.22
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/jre/lib
export MAVEN_HOME=/usr/local/java/apache-maven-3.3.1
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$MAVEN_HOME/bin


if [[ $deploy == "main" || $deploy == "all" ]]; then
  # sudo chmod -R 777  $main_
  # pwd
  echo main--------$main_----------main
  if [ ! -d "$main_" ]; then
      echo "找不到Main入口文件"
      exit
  fi

  echo "=========================启动Main开始==============================="
  sudo chmod -R +x $main_/
  cd $main_
  echo "=========================main path==============================="
  pwd
  echo "=========================main path==============================="
  # $main_/stop.sh
  sh ./start.sh
  tail -1 $main_/nohup.out
  echo "=========================启动Main开始==============================="
fi

if [[ $deploy == "gateway" || $deploy == "all" || $deploy == "webgateway" ]]; then
  #起gateway
  gatewayPath=$service/$project-gateway
  echo "=========================gatewayPath==============================="
  echo $gatewayPath
  echo "=========================gatewayPath==============================="

  if [ -d "$gatewayPath" ]; then
      echo "=========================启动gateway开始==============================="
      sudo chmod +x $gatewayPath/tomcat.sh
      cd $gatewayPath
      echo "=========================gateway==============================="
      pwd
      echo "=========================gateway==============================="
      #  $service/$project-gateway/tomcat.sh stop
      sudo ./tomcat.sh start
      echo "=========================启动gateway结束==============================="

  else

      echo "=========================当前无gatewayPath==============================="
      echo "当前无gatewayPath:" $gatewayPath
      echo "=========================当前无gatewayPath==============================="

  fi
fi

if [[ $deploy == "web" || $deploy == "all" || $deploy == "webgateway" ]]; then
  #起web
  webPath=$service/$project
  echo "=========================webPath==============================="
  echo $webPath
  echo "=========================webPath==============================="

  if [ -d "$webPath" ]; then
      echo "=========================启动web开始==============================="
      sudo chmod +x $webPath/tomcat.sh
      cd $webPath
      echo "=========================tomcat==============================="
      pwd
      echo "=========================tomcat==============================="
      #  $service/$project/tomcat.sh stop
      sudo ./tomcat.sh start
      echo "=========================启动web结束==============================="

  else

      echo "=========================当前无webPath==============================="
      echo "当前无webPath:" $webPath
      echo "=========================当前无webPath==============================="
  fi
fi

echo "=========================打印当前起的端口:==============================="
ps -ef | grep $project
echo "=========================打印当前终的端口:==============================="

Jason.wang

When you find your talent can't afford to be ambitious, be quiet and study !

You may also like...