強制重啓tomcat的sh

我寫的狗屎

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章