Ubuntu Linux重启Tomcat服务Shell脚本

前端之家收集整理的这篇文章主要介绍了Ubuntu Linux重启Tomcat服务Shell脚本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/sh
#定义tomcat路径变量:完整路径或最后级路径文件夹都可以
tomcat_path='/usr/dev/tomcat' 
#获取 tomcat_path 所知tomcat 的进程ID
TomcatID=$(ps -ef |grep tomcat |grep -w $tomcat_path|grep -v 'grep'|awk '{print $2}')
echo "##############################################开始重启Tomcat Server[$tomcat_path、进程ID:$TomcatID]################################################"
#判断进程是否存在 注意空格,if用法参照http://blog.chinaunix.net/uid-20735106-id-3434959.html
if [ "$TomcatID" != "" ] ; then
  echo "Tomcat Server[$tomcat_path、进程ID:$TomcatID] Was Started! Begin To Shutdown Tomcat Server!"
  sh /usr/dev/tomcat/bin/shutdown.sh
  echo "Tomcat Server[$tomcat_path] Was Shutdown! Begin To Restart Tomcat Server!"
  sh /usr/dev/tomcat/bin/startup.sh
  echo "Tomcat Server[$tomcat_path] Was Started!"
else
  echo "Tomcat Server[$tomcat_path] Has Not Started! Begin to Start Tomcat Server!"
  sh /usr/dev/tomcat/bin/startup.sh
  echo "Tomcat Server[$tomcat_path] Was Started!"
fi
NewTomcatID=$(ps -ef |grep tomcat |grep -w $tomcat_path|grep -v 'grep'|awk '{print $2}')
if [ "$NewTomcatID" != "" ] ; then
  echo "#############################################Success:Tomcat Server[$tomcat_path、进程ID:$NewTomcatID]重启完毕!#############################################"
else
  echo "################################################Fail:Tomcat Server[$tomcat_path]重启失败!############################################"
fi
原文链接:https://www.f2er.com/ubuntu/353835.html

猜你在找的Ubuntu相关文章