首页 > 系统服务 > 详细

shell -- sample -- 关闭tomcat

时间:2017-02-09 00:22:51      阅读:325      评论:0      收藏:0      [点我收藏+]
#!/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

原文:http://www.cnblogs.com/drizzlewithwind/p/6370194.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!