部署Test Java 环境

#!/bin/bash

# 部署Test Java 环境
#Author: Jasonote
#Date  : 2017/05/24
#version: 1.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"
  read -p "Please input a number:(Default 1 press Enter) " Choose_number
  [ -z "${Choose_number}" ] && Choose_number=1
  if [[ ! ${Choose_number} =~ ^[1-4]$ ]]; then
    echo "input error! Please only input number 1,2,3,4"
  else
    break
  fi
done
case "${Choose_number}" in
  1)
    project=auto-order
    ;;
  2)
    project=new-srm
    ;;
  3)
    project=pms-product
    ;;
  4)
    project=smart-alarm
    ;;
esac

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


code=$dr/$project

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

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程序
if [[ $project == "new-srm" ]]; then
	key="supplier"
else
	key=$project
fi

echo key--------$key----------key
main_=$code/$key-main/target/$key-main-1.0-SNAPSHOT/$key-main-1.0-SNAPSHOT/bin
# sudo chmod -R 777  $main_
# pwd
if [ ! -d "$main_" ]; then 
	echo "找不到Main入口文件"
	exit
fi

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

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开始==============================="

#起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


#起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

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...