Skip to content

Instantly share code, notes, and snippets.

@kkaushal09
Created September 24, 2018 07:32
Show Gist options
  • Save kkaushal09/d001205c0686f743299fd63d0edc259b to your computer and use it in GitHub Desktop.
Save kkaushal09/d001205c0686f743299fd63d0edc259b to your computer and use it in GitHub Desktop.
Shell script to monitor tomcat is alive on port 8080
#!/bin/sh
da=`date`
HOST=127.0.0.1
PORT=8080
#infinite loop
#while [ 1 ]
#do
#try to access tomcat's page
RES=`timeout 120 wget -O - -o /dev/null --proxy=off http://${HOST}:${PORT}/isalive.html | awk '{ print $1 }'`
echo got ${RES}
#decide on reply
if [ "$RES" = "YES" ]
then
echo tomcat is responding on $HOST:$PORT
else
echo tomcat seems to be dead.
echo Killing...
#for thepin in `ps -Af | grep -v grep | grep tomcat | grep catalina | awk '{ print $2 }'`
for thepin in ` ps -Af | grep java | grep catalina | grep "7.0.42" | grep -v grep | awk '{ print $2 }'`
do
kill -9 ${thepin}
done
echo -e "Starting... at $da"
#sudo -u tomcat /usr/local/apache-tomcat-inst2/bin/startup.sh
/etc/init.d/tomcat start
echo -e "Tomcat has been restarted automatically. PLEASE VERIFY everything is working fine..." | mutt -s "Tomcat RESTART event on Wifive LIVE server" -c "techops@taskbucks.work" -e "my_hdr From: Report <report@wifiveapp.com>" server@wifiveapp.com vikram.gupta@taskbucks.work brijesh@wifiveapp.com arvinder@taskbucks.work
fi
#sleep 60
#done
###*/3 * * * * bash -l /home/kishlay/tomcatWatchdog.sh >> /home/kishlay/tomcatWatchdog.log 2>&1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment