zoukankan      html  css  js  c++  java
  • 15 自动发布Java项目(Tomcat)

    #!/bin/bash
    export PAHT=/usr/local/maven/bin:/usr/local/jdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
    
    DATE=$(date +%F_%T)
    TOMCAT_NAME=$1
    TOMCAT_DIR=/usr/local/$TOMCAT_NAME
    ROOT=$TOMCAT_DIR/webapps/ROOT
    
    BACKUP_DIR=/data/code_backup
    [ ! -d $BACKUP_DIR ] && mkdir -p $BACKUP_DIR
    WORK_DIR=/tmp
    PROJECT_NAME=tomcat-java-demo
    
    # 拉取代码
    cd $WORK_DIR
    if [ ! -d $PROJECT_NAME ]; then
       git clone https://github.com/lizhenliang/tomcat-java-demo
       cd $PROJECT_NAME
    else
       cd $PROJECT_NAME
       git pull
    fi
    
    # 构建
    mvn clean package -Dmaven.test.skip=true
    if [ $? -ne 0 ]; then
       echo "maven build failure!"
       exit 1
    fi
    
    # 部署
    TOMCAT_PID=$(ps -ef |grep "$TOMCAT_NAME" |egrep -v "grep|$$" |awk 'NR==1{print $2}')
    [ -n "$TOMCAT_PID" ] && kill -9 $TOMCAT_PID
    [ -d $ROOT ] && mv $ROOT $BACKUP_DIR/${TOMCAT_NAME}_ROOT$DATE
    unzip $WORK_DIR/$PROJECT_NAME/target/*.war -d $ROOT
    # $TOMCAT_DIR/bin/startup.sh
    systemctl start $TOMCAT_NAME
    
    
    # USAGE
    # maven、jdk、tomcat 环境
    # bash <脚本> <部署的 tomcat 名称>
    # 例:bash 15AutomaticallyReleaseJavaProject(Tomcat).sh test_tomcat
    # test_tomcat:具体地址为 /usr/local/test_tomcat/
    # 后台运行:nohup bash 15AutomaticallyReleaseJavaProject(Tomcat).sh test_tomcat > tomcat_out.txt 2>&1 &
    # 访问:http://<IP>:8080/
  • 相关阅读:
    测试随笔
    ECNU 3530 和你在一起
    ECNU 1030 母牛生小牛
    ECNU 3081 购房还款
    PPP模式下的融资结构优化
    决策树分类
    关联规则-R语言实现
    中国快递包裹总量的预测-基于SARIMA模型
    LeetCode 2 :Swap Nodes in Pairs
    2018092609-2 选题 Scrum立会报告+燃尽图 04
  • 原文地址:https://www.cnblogs.com/LiuChang-blog/p/14697978.html
Copyright © 2011-2022 走看看