码迷,mamicode.com
首页 > 其他好文 > 详细

强制重启tomcat的sh

时间:2019-05-28 17:22:48      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:rgs   not run   rest   开始   tom   uid   $2   online   存在   

我写的狗屎

ps aux |grep tomcat_9090_uba |grep -v grep &>/dev/null 
if  [ $? -ne 0 ];then
     sh /home/tomcat_9090_uba/bin/startup.sh &>/dev/null
      echo "tomcat9090 start"
else
    ps aux |grep tomcat_9090_uba --color=auto |grep -v grep |awk ‘{print $2}‘ |xargs kill -9 && echo "tomcat9090 online"
   sh /tmp/duidui.sh
fi

这。。。唉

ps aux |grep -v grep | grep tomcat_9090_uba  &>/dev/null 
# 如果pid不存在,$?为非零,即直接重启
if  [ $? -ne 0 ];then 
    echo "tomcat9090 is not running"
    sh /home/tomcat_9090_uba/bin/startup.sh &>/dev/null
    pid=`ps aux |grep -v grep |grep tomcat_9090_uba | awk ‘{print $2}‘`
    echo "start tomcat9090 successfully, the pid is $pid"
# 如果pid存在,先kill掉,然后再重启
else
    pid=`ps aux |grep -v grep |grep tomcat_9090_uba | awk ‘{print $2}‘`
    echo "tomcat is running, the pid is $pid"
    echo "Prepare to force restart tomcat_9090_uba"
    # 杀掉tomcat
    kill -9 $pid
    sleep 2
    ps aux |grep -v grep | grep tomcat_9090_uba  &>/dev/null
        if [ $? -ne 0 ];then
            echo "tomcat_9090_uba is killed"
        fi
    # 开始重新启动tomcat
    echo "start tomcat9090"
    sh /home/tomcat_9090_uba/bin/startup.sh &>/dev/null
    # 检查是否存在存在进程
    ps aux |grep -v grep | grep tomcat_9090_uba  &>/dev/null
    if [ $? -eq 0 ];then
        # 获取重启之后的pid号
        pid=`ps aux |grep -v grep |grep tomcat_9090_uba | awk ‘{print $2}‘`
        echo "restart tomcat9090 successfully, the pid is $pid"
    fi
    sh /tmp/duidui.sh
fi

强制重启tomcat的sh

标签:rgs   not run   rest   开始   tom   uid   $2   online   存在   

原文地址:https://blog.51cto.com/xiaoahehe/2401532

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!