Skip to content

Instantly share code, notes, and snippets.

@xezpeleta
Created December 13, 2018 08:04
Show Gist options
  • Save xezpeleta/434784a705c02885b59e494cdeed3ecd to your computer and use it in GitHub Desktop.
Save xezpeleta/434784a705c02885b59e494cdeed3ecd to your computer and use it in GitHub Desktop.
Tomcat auto-recovery
#! /bin/bash
URL=http://localhost
LOGFILE=/root/scripts/mywebapp_recovery.log
TIMEOUT=5
response=`curl -m $TIMEOUT -s -o /dev/null -w "%{http_code}" $URL`
if [[ "$response" != 200 ]];then
printf '[%(%d/%b/%Y:%H:%M:%S %z)T] Response code: %s\n' -1 "$response" >> $LOGFILE
# Shutdown Tomcat
/opt/liferay6100/tomcat-7.0.23/bin/shutdown.sh
sleep 10
# Still alive? Let's kill it properly
killall java
sleep 5
# Well, sorry but now yes, you have to die
killall -9 java
# Start Tomcat
/opt/liferay6100/tomcat-7.0.23/bin/startup.sh
printf '[%(%d/%b/%Y:%H:%M:%S %z)T] Mywebapp service restored: %s\n' -1 "$?" >> $LOGFILE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment