强制重启tomcat的sh

ぃ、小莉子 提交于 2020-01-23 09:46:52

我写的狗屎

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!