tomcat快速部署脚本1.3

#!/bin/bash
#-*- coding: utf-8 -*-
#Date:   2020/03/30
#Author:  Mr.yang
#Version: 1.3

tomcat6=""
tomcat61=""
tomcat62=""
tomcat63=""
tomcat7=""
tomcat8=""
tomcat81=""
tomcat82=""
tomcat83=""
i="0"

function choose(){
cat << KOF
*************************************************
*        1.测试环境项目部署        *
*        2.正式环境项目部署        *
*************************************************
KOF
}

function test(){
read -p "请输入项目名:" pjname
    name=`echo ${pjname} | sed 's/-//g'`
read -p "请输入平台名称:" platform && read -p "请输入用户密码:" passwd
    mkdir -p /webapp/${platform}${pjname}
    mkdir -p /logs/${pjname}
    useradd ${platform}${name}
    echo "${passwd}" | passwd --stdin ${platform}${name}
read -p "请输入端口号(关闭端口自动+1000):" prot
    while [ $i -le 3 ]
    do
                fin=`find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l`
                find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l
                if [ $fin != 0 ];then
                        echo "端口目录存在……" && read -p "请重新输入端口号:" prot
                        i=$((i+1))
                        if [ $i < 3 ];then
                                continue
                        elif [ $i == 3 ];then
                                echo "请仔细核对端口后,再次执行……"
                                exit
                        fi
                        ps -ef |grep $prot | grep -v grep
                        if [ $? -eq 0 ];then
                                echo "启用端口重复……" && read -p "请重新输入:" prot
                        elif [ $? -ne 0 ];then
                                echo "无端口重复,继续进行……"
                                break
                        fi
                elif [ $fin == 0 ];then
                        echo "无端口重复……"
                        break
                fi
        done
read -p "请输入tomcat版本(输入6/8):" tomcat
    cd /webapp/${platform}${pjname}
    if [ $tomcat == 6 ];then
        wget $tomcat6
    elif [ $tomcat == 7 ];then
        wget $tomcat7
    elif [ $tomcat == 8 ];then
        wget $tomcat8
    fi
}

function product(){
read -p "请输入项目名:" pjname
read -p "请输入平台名称:" platform && read -p "请输入用户密码:" passwd && read -p "请输入UID:" uid
    name=`echo ${pjname} | sed 's/-//g'`
    mkdir -p /webapp/${platform}${pjname}
    mkdir -p /logs/${pjname}
    useradd -u ${uid} ${platform}${name}
    echo "$passwd" | passwd --stdin ${platform}${name}
read -p "请输入端口号(关闭端口自动+1000):" prot
    while [ $i -le 3 ]
    do
                fin=`find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l`
                find /webapp -mindepth 2 -maxdepth 2 |egrep tomcat_${prot} | wc -l
                if [ $fin != 0 ];then
                        echo "端口目录存在……" && read -p "请重新输入端口号:" prot
                        i=$((i+1))
                        if [ $i <= 3 ];then
                                continue
                        elif [ $i == 3 ];then
                                echo "请仔细核对端口后,再次执行……"
                                exit
                        fi
                        ps -ef |grep $prot | grep -v grep
                        if [ $? -eq 0 ];then
                                echo "启用端口重复……" && read -p "请重新输入:" prot
                        elif [ $? -ne 0 ];then
                                echo "无端口重复,继续进行……"
                                break
                        fi
                elif [ $fin == 0 ];then
                        echo "无端口重复……"
                        break
                fi
    done
read -p "请输入tomcat版本(6/8+1/2/3为低/中/高配置)\n(例61) :" tomcat
    cd /webapp/${platform}${pjname}
    if [ $tomcat == 61 ];then
        wget $tomcat61
    elif [ $tomcat == 62 ];then
        wget $tomcat62
    elif [ $tomcat == 63 ];then
        wget $tomcat63
    elif [ $tomcat == 81 ];then
        wget $tomcat81
    elif [ $tomcat == 82 ];then
        wget $tomcat82
    elif [ $tomcat == 83 ];then
        wget $tomcat83
    fi
}


function tomcat(){
    echo "创建中……请稍后……"
        tar=`ls | awk '/jdk/{print}'`
        tar xf /webapp/${platform}${pjname}/$tar && rm -rf /webapp/${platform}${pjname}/$tar
        gz=`ls | awk 'NR==1{print $1}'`
        mv /webapp/${platform}${pjname}/$gz /webapp/${platform}${pjname}/tomcat_$prot
        sed -i "s/8080/$prot/g" /webapp/${platform}${pjname}/tomcat_$prot/conf/server.xml
        Prot=$(($prot+1000))
        sed -i "s/9080/$Prot/g" /webapp/${platform}${pjname}/tomcat_$prot/conf/server.xml
        chown -R $platform$name.$platform$name /webapp/${platform}${pjname} /logs/${pjname}
        su - $platform$name -c "sh /webapp/${platform}${pjname}/tomcat_$prot/bin/startup.sh"
}

while :
do
    clear
    choose
    read -p "选择列表内容:" a
    case $a in
        1)
            test
            tomcat
            exit
            ;;
        2)
            product
            tomcat
            exit
            ;;
        *)
            echo "输入错误,请重新输入"
            sleep 2
            ;;
    esac
done

 

posted @ 2019-12-19 15:01  蜡笔没小新  阅读(258)  评论(0编辑  收藏  举报