shell -- sample -- 关闭tomcat

Posted RainDream

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell -- sample -- 关闭tomcat相关的知识,希望对你有一定的参考价值。

#!/bin/bash
process_name="org.apache.catalina.startup.Bootstrap"
shutdown_call=0
function shutdownTomcat() {
    process_pid=`ps -ef | grep "$process_name" | grep -v "grep" | awk { print $2 }`
    for i in $process_pid
    do
        echo "INFO: Kill the tomcat process [ $i ]"
        kill -9 $i
    done
    shutdown_call=1
}
function getProcessNum() {
    process_num=`ps -ef | grep "$process_name" | grep -v "grep" | wc -l`
    return $process_num
}
function checkYnAgain() {
    while true; do
    read -p "Please type \"Y\" or \"N\". " yn
    case $yn in
        [Yy]|[Yy][Ee][Ss] )
            shutdownTomcat
            break;;
        [Nn]|[Nn][Oo] )
            echo "exiting..."
            exit;;
    esac
    done
}
getProcessNum
tomcat_process_num=$?
if [ $tomcat_process_num -gt 0 ]; then
    echo "INFO: Tomcat server is running..."
    read -p "Do you want to shutdown tomcat server now [Y/N]? " yn
    case $yn in
        [Yy]|[Yy][Ee][Ss] )
            shutdownTomcat;;
        [Nn]|[Nn][Oo] )
            echo "exiting..."
            exit;;
        * )
            checkYnAgain;;
    esac
fi
getProcessNum
tomcat_process_num=$?
if [ $tomcat_process_num -gt 0 ]; then
    echo "ERROR: Fail to shutdown tomcat server."
    echo "You have to shutdown tomcat server or kill its process manually."
    exit 1
elif [ $shutdown_call -eq 1 ]; then
    echo "INFO: Shutdown tomcat server success."
fi

 

以上是关于shell -- sample -- 关闭tomcat的主要内容,如果未能解决你的问题,请参考以下文章

Tomcat 启动和关闭

linux shell 手动执行tomcat 和 计划任务重启tomcat 不一致。

部署Tomcat及负载均衡

Linux下Tomcat启动,停止命令

如何在python中比较2个json [关闭]

docker: Error response from daemon: driver failed programming external connectivity on endpoint tomc