Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
tomcat shutdown gracefully script
#!/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
You can’t perform that action at this time.