Code: Select all
#!/bin/bash -e
#Developed By [email protected]
while :
do
ESB_IP=192.168.200.86
SOAP_COMM_PORT=8290
HTTP_COMM_PORT=9453
#
SOAP_URI="http://$ESB_IP:$SOAP_COMM_PORT/services/echo?wsdl"
HTTPS_GUI="https://$ESB_IP:$HTTP_COMM_PORT/carbon/admin/login.jsp"
#
MEMINFO="/proc/meminfo"
PARK_LOC="/app"
JDK_BIN_LOC="$PARK_LOC/JAVADIR/jdk1.6.0_31/bin"
WSO2_HOME="$PARK_LOC/wso2esb-4.8.0"
THEDIR="$PARK_LOC/log/wso2-watchdog"
LOG="$PARK_LOC/log"
LOCKFILE="$PARK_LOC/log/is_ready"
#
LIMIT0=51
LIMIT1=90
LIMIT2=87
LIMIT3=89
LIMIT4=91
LIMIT5=99
#
MSG_HEADER="Maintain Log - Automated Mail From 2.86 ESB Server"
#
DATE=`date +%Y-%m-%d" "%H:%M:%S`
TOTAL=`cat $MEMINFO | grep MemTotal: | awk '{print $2}'`
USEDMEM=`cat $MEMINFO | grep Active: | awk '{print $2}'`
#
mkdir -p $THEDIR
if [ "$USEDMEM" -gt 0 ]
then
USEDMEMPER=$(($USEDMEM * 100 / $TOTAL))
USEDMEMPERLOG=$USEDMEMPER
if [[ $USEDMEMPER -gt $LIMIT2 && $USEDMEMPER -lt $LIMIT3 ]] ; then
echo "Memory in the Range... True"
if [ ! -f $LOCKFILE ]; then
find $THEDIR/ -type f -name '*.zip' -exec rm {} \;
find $LOG/ -type f -name '*.zip' -exec rm {} \;
echo "$DATE | Memory: $USEDMEMPER%, (limit: $LIMIT2%) "
WSO2_PID=`ps -ef | grep ClassLoaderLogManager | grep -v grep | awk '{print $2}'`
echo "Creating JAVA Thread Dump Time-wise...."
find $THEDIR/ -type f -name '*.dump' -exec rm {} \;
$JDK_BIN_LOC/jstack -l $WSO2_PID > $THEDIR/WSO2_Threaddump_$(date +"%m-%d-%Y_%H-%M").dump
cd $THEDIR ; zip -r WSO2_Treaddump.zip *
tail -n500 $WSO2_HOME/repository/logs/wso2carbon.log > $LOG/wso2carbon.log
cd $LOG ; zip -r wso2carbon.zip wso2carbon.log
echo $WSO2_PID > /dev/null
echo $USEDMEMPER > /dev/null
sleep 30
echo "JAVA Thread Dump Has Been Created...."
touch $LOCKFILE
fi
else
echo "Didn't Creating Thread Dump and Restarted.... "
fi
fi
USEDMEMPER=$(($USEDMEM * 100 / $TOTAL))
USEDMEMPERLOG=$USEDMEMPER
if [[ $USEDMEMPER -gt $LIMIT0 && $USEDMEMPER -lt $LIMIT1 ]] ; then
response_1=$(curl -k -s --head -w %{http_code} $SOAP_URI -o /dev/null)
response_2=$(curl -k -s --head -w %{http_code} $HTTPS_GUI -o /dev/null)
if [[ $response_1 -eq 200 && $response_2 -eq 200 ]] ; then
echo "The ESB is Up & Running..."
else
echo "This URL Not Exist"
TOTAL=`cat $MEMINFO | grep MemTotal: | awk '{print $2}'`
USEDMEM=`cat $MEMINFO | grep Active: | awk '{print $2}'`
USEDMEMPER=$(($USEDMEM * 100 / $TOTAL))
echo "$DATE | Memory Limit Reached ($LIMIT%): Used Memory Before ESB Restart $USEDMEMPERLOG% | Memory Before ESB Restart: $USEDMEMPER%" >> $LOG/esb-free.log
echo $USEDMEMPER > /dev/null
tail -1 $LOG/esb-free.log
echo "killing all the Java PIDs at Once on Live ESB...."
kill -9 `ps -ef | grep wso2esb-4.8.0 | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
echo "Waiting 20s to start ...."
sleep 20
kill -9 `ps -ef | grep wso2esb-4.8.0 | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
echo "Stating WSO2_ESB Service...."
nohup sh $WSO2_HOME/bin/wso2server.sh >> $WSO2_HOME/repository/logs/wso2carbon.log
TOTAL=`cat $MEMINFO | grep MemTotal: | awk '{print $2}'`
USEDMEM=`cat $MEMINFO | grep Active: | awk '{print $2}'`
USEDMEMPER=$(($USEDMEM * 100 / $TOTAL))
echo "$DATE | Memory Limit Reached ($LIMIT%): Used Memory After ESB Restart $USEDMEMPERLOG% | Memory After ESB Restart: $USEDMEMPER%" >> $LOG/esb-free.log
RST01=`echo "$DATE | Memory Limit Reached ($LIMIT%): Used Memory After ESB Restart $USEDMEMPERLOG% | Memory After ESB Restart: $USEDMEMPER%"`
echo "Result = $RST01 and JAVA Thread Dump Has Been Created @ Server 200.86" | mail -a $LOG/esb-free.log -a $LOG/wso2carbon.zip -a $THEDIR/*.zip -s "$MSG_HEADER" [email protected],[email protected]
echo $USEDMEMPER > /dev/null
tail -1 $LOG/esb-free.log
sleep 15
fi
fi
USEDMEMPER=$(($USEDMEM * 100 / $TOTAL))
USEDMEMPERLOG=$USEDMEMPER
if [[ $USEDMEMPER -gt $LIMIT4 && $USEDMEMPER -lt $LIMIT5 ]] ; then
TOTAL=`cat $MEMINFO | grep MemTotal: | awk '{print $2}'`
USEDMEM=`cat $MEMINFO | grep Active: | awk '{print $2}'`
USEDMEMPER=$(($USEDMEM * 100 / $TOTAL))
echo "$DATE | Memory Limit Reached ($LIMIT%): Used Memory Before ESB Restart $USEDMEMPERLOG% | Memory Before ESB Restart: $USEDMEMPER%" >> $LOG/esb-free.log
echo $USEDMEMPER > /dev/null
tail -1 $LOG/esb-free.log
echo "killing all the Java PIDs at Once on Live ESB...."
kill -9 `ps -ef | grep wso2esb-4.8.0 | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
echo "Waiting 20s to start ...."
sleep 20
kill -9 `ps -ef | grep wso2esb-4.8.0 | grep -v grep | awk '{print $2}'` > /dev/null 2>&1
free && sync && echo 3 > /proc/sys/vm/drop_caches && free
echo "Stating WSO2_ESB Service...."
nohup sh $WSO2_HOME/bin/wso2server.sh >> $WSO2_HOME/repository/logs/wso2carbon.log > /dev/null 2>&1 &
TOTAL=`cat $MEMINFO | grep MemTotal: | awk '{print $2}'`
USEDMEM=`cat $MEMINFO | grep Active: | awk '{print $2}'`
USEDMEMPER=$(($USEDMEM * 100 / $TOTAL))
echo "$DATE | Memory Limit Reached ($LIMIT%): Used Memory After ESB Restart $USEDMEMPERLOG% | Memory After ESB Restart: $USEDMEMPER%" >> $LOG/esb-free.log
RST01=`echo "$DATE | Memory Limit Reached ($LIMIT%): Used Memory After ESB Restart $USEDMEMPERLOG% | Memory After ESB Restart: $USEDMEMPER%"`
echo "Result = $RST01 and JAVA Thread Dump Has Been Created @ Server 200.86" | mail -a $LOG/esb-free.log -a $LOG/wso2carbon.zip -a $THEDIR/*.zip -s "$MSG_HEADER" [email protected],[email protected]
echo $USEDMEMPER > /dev/null
tail -1 $LOG/esb-free.log
sleep 15
fi
find /app/log/is_ready -type f -mmin +20 -exec rm {} \; > /dev/null 2>&1
#nohup sh /app/ESB_Maintain_Script/wso_auto_maintain.sh > /dev/null 2>&1 &
sleep 10
done