Stop Tomcat from running the script code under CentOS

  • 2020-05-10 23:17:27
  • OfStack

The code is validated and retained for later use


#!/bin/sh
#
# Firstly find the process of the tomcat....
TOMCAT_PROCESS_STR=`ps aux | grep 'java.*tomcat' | grep -v grep`
PROCESS_ARRAY=(${TOMCAT_PROCESS_STR// / })
TOMCAT_PROCESS_ID=${PROCESS_ARRAY[1]}
echo $TOMCAT_PROCESS_ID
#
# Secondly send stop tomcat to see if we can kill it
stoptomcat
sleep 12
#
# Last we'll use kill tomcat process in a looking up loop
for ((a=1;a<=10;a++))
do
 CHECK_STR_LENGTH=0
 TOMCAT_PROCESS_CHECK_STR=`ps aux | grep 'java.*tomcat' | grep -v grep`
 CHECK_STR_LENGTH=${#TOMCAT_PROCESS_CHECK_STR}
#  The number of parameters passed to the script; 
 if [ $CHECK_STR_LENGTH != 0 ]
 then
  kill $TOMCAT_PROCESS_ID
  sleep 5
  echo Try to kill tomcat once more...
 else
  echo Tomcat is already killed
  break
 fi
done
# Use twice grep To remove grep The native process is very skilled at interfering with the search results 

Related articles: