November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

websphere restart script

#!/bin/ksh

BASENAME=`basename $0`

WAZZZ_HOME=/usr/WebSphere/AppServer
JVVVM_BIN_DIR=$WAZZZ_HOME/profiles/node01/bin

die_usage()
{
echo “usage: $BASENAME: <jvm name> <timeout> <hard retries>”
exit $1
}

[[ $# -eq 3 ]] || die_usage 111

JVVVM_NAME=$1
TIMEOUT=$2
HARD_RETRIES=$3

JVVVM_LOG_DIR=$WAZZZ_HOME/profiles/node01/logs/$JVVVM_NAME
JVVVM_PID=

$JVVVM_BIN_DIR/serverStatus.sh -all | grep ” $JVVVM_NAME” | grep -v grep | grep -v $BASENAME > /dev/null 2>&1

if [[ $? -ne 0 ]]
then
echo “usage: $BASENAME: $JVVVM_NAME is not a recognized WAS 6 jvm.”
exit 111
fi

if [[ -e $JVVVM_LOG_DIR/${JVVVM_NAME}.pid ]]
then
# First lets verify that this PID is actually running
PS_PID=$(ps auxwww | grep ” $JVVVM_NAME” | grep -v grep | grep -v $BASENAME | awk -F” ” ‘{print $2}’ | head -1)

# Lets get the PID from the JVVVM’s pid file
FILE_PID=$(cat $JVVVM_LOG_DIR/${JVVVM_NAME}.pid)

if [[ $PS_PID -eq $FILE_PID ]]
then
JVVVM_PID=$FILE_PID
else
JVVVM_PID=$PS_PID
fi
fi

echo “INFO: $BASENAME: Stopping the $JVVVM_NAME JVM with process id: $JVVVM_PID”
# At this point the JVVVM should be running, lets kill it
# This is a timed stop.  It will run for the specified
# Timeout value before killing itself in disgust

echo “INFO: $BASENAME: Attempting graceful stop of $JVVVM_NAME…”
$JVVVM_BIN_DIR/stopServer.sh $JVVVM_NAME > /dev/null 2>&1 & {
sleep ${TIMEOUT} > /dev/null 2>&1
eval ‘kill -9 $! > /dev/null 2>&1’
}

#
# Do another quick check to see it is still running
#
ps auxwww| grep ” $JVVVM_NAME” | grep -v grep | grep -v $BASENAME > /dev/null 2>&1
IS_RUNNING=$?

if [[ $IS_RUNNING -eq 0 ]]
then
echo “WARN: $BASENAME: Graceful stop failed.  Entering hard kill loop…”
COUNT=1
while ((COUNT < HARD_RETRIES))
do
PIDID=$(ps auxwww | grep ” $JVVVM_NAME” | grep -v grep | grep -v $BASENAME | awk -F” ” ‘{print $2}’ | head -1)
echo “INFO: $BASENAME: Trying to hard stop the JVM process: ${PIDID} Count: ${COUNT}…”
kill -9 ${PIDID}
((COUNT = COUNT + 1))
sleep 7
done
fi

echo “INFO: $BASENAME: $JVVVM_NAME has been stopped.”

exit 0

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>