linux git拉取代码 脚本一键部署项目发布

#!/bin/bash
. /etc/profile

PROG="pinyu"
service tomcat-$PROG stop

TOMCAT_DIR="/usr/tomcat/tomcat-$PROG-80"
DIR="/usr/git/pinyu"
cd $DIR
git pull
mvn clean package -Dmaven.test.skip=true


rm -rf $TOMCAT_DIR/webapps/pinyu*
cp -R $DIR/target/pinyu $TOMCAT_DIR/webapps/pinyu

service tomcat-$PROG start

 

或者以杀死进程的方式:


#!/bin/bash

TOMCAT_DIR="/root/huliangyu/apache-tomcat-8.5.32"
SOURCE_DIR="/root/huliangyu/shentb_services/shentb_services"
TOMCAT_SERVICE="tomcat"

pid=`ps -ef | grep $TOMCAT_SERVICE | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
   kill -9 $pid
   echo "closed process"$pid
fi
cd $SOURCE_DIR
git pull
mvn clean package -Dmaven.test.skip=true
rm -rf $TOMCAT_DIR/webapps/shentb-0.0.1.war
cp -r $SOURCE_DIR/target/shentb-0.0.1.war $TOMCAT_DIR/webapps/shentb-0.0.1.war
service $TOMCAT_SERVICE start

或者通过端口号杀死PID

#!/bin/bash

TOMCAT_DIR="/root/huliangyu/apache-tomcat-8.5.32"
SOURCE_DIR="/root/huliangyu/shentb_services/shentb_services"
TOMCAT_SERVICE="tomcat-stb_yupanpan"

#pid=`ps -ef | grep $TOMCAT_SERVICE | grep -v grep | awk '{print $2}'`
pid=`lsof -i:8888 | awk '{print $2}'`
if [ -n "$pid" ]
then
   kill -9 $pid
   echo "closed process"$pid
fi
cd $SOURCE_DIR
git pull
mvn clean package -Dmaven.test.skip=true
rm -rf $TOMCAT_DIR/webapps/shentb-0.0.1.war
cp -r $SOURCE_DIR/target/shentb-0.0.1.war $TOMCAT_DIR/webapps/shentb-0.0.1.war
service $TOMCAT_SERVICE start
 

`ps -ef | grep $TOMCAT_SERVICE | grep -v grep | awk '{print $2}'`的意思是查找有关$TOMCAT_SERVICE的服务并过滤掉本身的grep进程 获取PID

linux git拉取代码 脚本一键部署项目发布_第1张图片

 

 

 

 

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