• shell脚本自动化部署服务


    shell脚本自动化部署

    !/bin/bash
    
    #export PATH=$PATH:/export/maven/bin
    
    run_flag_dir="/data0/shell/deploy_workspace/Test"
    if [ ! -d "$run_flag_dir" ]; then
        mkdir -p "$run_flag_dir"
    fi
    
    #判断是否正在部署,如果是则退出
    if [ -f "$run_flag_dir/.run" ]; then
        echo "程序部署中,请勿重复部署!"
        exit 1
    fi
    
    #创建.run文件,标识脚本正在部署
    touch "$run_flag_dir/.run"
    #捕获Ctrl+C,删除.run文件,避免状态不一致
    trap "rm -r $run_flag_dir/.run; exit 1" 2
    
    export JAVA_HOME=/data0/usr/jdk1.8.0_60/
    
    /bin/rm -rf ./deploy_workspace/Test
    
    echo "##############################################################"
    echo "开始git下载代码。。。"
    echo "##############################################################"
    
    cd /data0/shell/deploy_workspace
    if [ ! -d "Test" ]; then
        git clone -b dev git@git.jd.com:AIBDP-Mobile/Test.git
        cd Test
        git pull
    else
        cd Test
        git pull
    fi
    
    
    echo "##############################################################"
    echo "开始编译代码。。。"
    echo "##############################################################"
    cd /data0/shell/deploy_workspace/Test/
    #cp -rf face-web/src/main/config/test/* ai-web/src/main/resources/
    #/bin/rm -rf mobile-web/src/main/config/test/jss.properties
    cp -rf web/src/main/config/test/* web/src/main/resources/
    mvn clean package -U -DskipTests -Dmaven.repo.local=/data0/repository
    #mvn clean package  -DskipTests
    
    
    
    if [ $? != 0 ]; then
        echo "##############################################################"
        echo -e 'mvn打包出错了,直接退出部署程序。。。';
        echo "##############################################################"
        /bin/rm -rf $run_flag_dir/.run;
        exit 1
    fi
    
    
    
    
    echo "##############################################################"
    echo "开始停止tomcat。。。"
    echo "##############################################################"
    sh  /data0/usr/apache-tomcat-8.5.24/bin/shutdown.sh
    sleep 3
    ps -ef| grep "apache-tomcat-8.5.24" | grep -v grep |  awk  '{print $2}' | xargs kill -9
    echo "====tomcat服务已停止成功。。。"
    echo "##############################################################"
    
    echo "##############################################################"
    echo -e "开始部署程序。。。"
    echo "##############################################################"
    cd /data0/shell/deploy_workspace/Test/
    /bin/rm -rf /data0/usr/apache-tomcat-8.5.24/webapps/ROOT*
    unzip -q  mobile-web/target/ROOT.war -d  "/data0/usr/apache-tomcat-8.5.24/webapps/ROOT"
    
    
    
    echo "##############################################################"
    echo -e "开始启动tomcat。。。"
    echo "##############################################################"
    export CATALINA_OPTS="-Xms1024M -Xmx1024M -server -XX:PermSize=256M"
    nohup sh /data0/usr/apache-tomcat-8.5.24/bin/startup.sh &
    
    
    #删除.run文件,部署完毕
    /bin/rm -rf $run_flag_dir/.run;
    
    echo "##############################################################"
    echo -e "开始打印日志。。。"
    echo "##############################################################"
    
    tail -f  "/data0/usr/apache-tomcat-8.5.24/logs/catalina.out"
    View Code
  • 相关阅读:
    tty & pty & pts
    PageRank
    How to run a terminal inside of vim?
    vimdiff
    svn's tree conflict
    svn's diff command
    符号表分离
    gcc -D
    Options for Debugging Your Program or GCC
    invoking gdb
  • 原文地址:https://www.cnblogs.com/zgzf/p/10525146.html
Copyright © 2020-2023  润新知