tomcat重启脚本

#!/bin/bash
RED=’\E[1;31m’
GRN=’\E[1;32m’
RES=’\E[0m’
tomcat_name=”tomcat-guanli”
tomcat_log=”/project/opt/${tomcat_name}/logs/catalina.out”
tomcat_start=”/project/opt/${tomcat_name}/bin/startup.sh”
tomcat_pid=`ps aux | grep ${tomcat_name} | grep -v grep | awk ‘{print $2}’`
if [ ! ${tomcat_pid} ];then
echo -e “${RED}tomcat not start…${RES}”
echo -e “${RED}please start tomcat…${RES}”
echo -e “${GRN}start ${tomcat_name}now…${RES}”
sleep 1
sh $tomcat_start ; tail -f $tomcat_log
else
echo -e “${GRN}tomcat pid is ${tomcat_pid} ${RES}”
echo -e “${RED}kill ${tomcat_name}…${RES}”
kill -9 $tomcat_pid
sleep 1
echo -e “${GRN}start ${tomcat_name}…${RES}”
sh $tomcat_start ;tail -f $tomcat_log
fi

《tomcat重启脚本》有1个想法

  1. 以下是优化版的脚本

    #!/bin/bash
    # 使用该脚本的话,需要把该脚本放到tomcat的bin目录下
    RED=’\E[1;31m’
    GRN=’\E[1;32m’
    RES=’\E[0m’
    cd `dirname $0`
    cd ../
    tomcat_name=`pwd | awk -F”/” ‘{print $NF}’`
    tomcat_log=”logs/catalina.out”
    tomcat_start=”bin/startup.sh”
    tomcat_pid=`ps aux | grep ${tomcat_name} | grep -v grep | grep -v $$ | awk ‘{print $2}’`
    echo ${tomcat_pid}

    #sleep 100

    if [[ ! ${tomcat_pid} ]];then
    echo -e “${RED}tomcat not start…${RES}”
    echo -e “${RED}please start tomcat…${RES}”
    echo -e “${GRN}start ${tomcat_name}now…${RES}”
    sleep 1
    sh $tomcat_start ; tail -f $tomcat_log
    else
    echo -e “${GRN}tomcat pid is ${tomcat_pid} ${RES}”
    echo -e “${RED}kill ${tomcat_name}…${RES}”
    kill -9 $tomcat_pid
    sleep 1
    echo -e “${GRN}start ${tomcat_name}…${RES}”
    sh $tomcat_start ;tail -f $tomcat_log
    fi

发表评论

电子邮件地址不会被公开。 必填项已用*标注