Last active
August 26, 2020 08:42
-
-
Save lesstif/18c9923c46aa4341b83b to your computer and use it in GitHub Desktop.
tomcat shutdown gracefully script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
killproc() { | |
local servicename=$1 | |
local user=$2 | |
local signal="TERM" | |
if [ "$#" = 0 ] ; then | |
echo $"Usage: killproc {servicename} {user} {signal}" | |
return 1 | |
fi | |
if [ "$#" = 3 ]; then | |
signal=$3 | |
fi | |
PIDS=`ps -eaf|grep ${servicename}|grep -v grep|grep ${user}|awk '{print $2}'` | |
## process still running.. | |
for p in ${PIDS} | |
do | |
if [ ! -z ${p} ] && [ ${p} -gt 0 ];then | |
echo "kill -${signal} ${p}" | |
kill -${signal} ${p}; | |
return $?; | |
else | |
return 0; | |
fi | |
done | |
} | |
## tomcat instance name. recommended tomcat running with custom property (aka -Dcom.example.servicename=myWebApp ) | |
SERVICE_NAME=myWebApp | |
## tomcat home | |
TC_HOME=/var/tomcat/tomcat-7.0.55 | |
if [ ! -d ${TC_HOME} ];then | |
TC_HOME=`pwd` | |
fi | |
## tomcat process owner name | |
USER=`whoami` | |
cd ${TC_HOME} | |
./bin/shutdown.sh >& /dev/null | |
sleep 1 # delay 1 sec for tomcat shutting down.. | |
## | |
for i in 1 2;do | |
killproc ${SERVICE_NAME} ${USER} | |
RET=$? | |
if [ $RET = 0 ];then | |
break; | |
fi; | |
sleep $i; | |
done | |
## if still running send KILL signal | |
killproc "${SERVICE_NAME}" "${USER}" "KILL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment