Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements to the tomcat checkup script.
- Loading branch information
1 parent
3607b26
commit b55b9c6
Showing
1 changed file
with
31 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,45 @@ | ||
#!/bin/bash | ||
|
||
if [ ! "$1" ]; then | ||
echo "Tomcat directory required."; | ||
echo "USAGE: bin/checkup.sh TOMCAT_DIRECTORY"; | ||
echo "Tomcat directory required." >&2 | ||
echo "USAGE: bin/checkup.sh TOMCAT_DIRECTORY" >&2 | ||
exit 1; | ||
elif [ ! -d "$1" ]; then | ||
echo "$1 is not a valid directory." >&2 | ||
echo "USAGE: bin/checkup.sh TOMCAT_DIRECTORY" >&2 | ||
exit 1; | ||
fi | ||
|
||
TOMCAT=$1 | ||
DATE=`date` | ||
PID=`ps -ef | grep tomcat | grep -v $0 | grep -v grep | tr -s " " "|" | cut -d "|" -f 2` | ||
TOMCAT_DIR="$1" | ||
|
||
cd $TOMCAT | ||
echo "$DATE - Running checkup" | ||
|
||
# This attempts to find the tomcat pid by grepping on tomcat and catalina.base. | ||
# TODO: Look into the CATALINA_PID option in catalina.sh | ||
PID=`ps -ef | grep tomcat | grep "catalina.base" | tr -s " " "|" | cut -d "|" -f 2` | ||
if [ ! -n "$PID" ]; then | ||
echo "$DATE - tomcat was down" >&2 | ||
bin/startup.sh | ||
exit 1 | ||
echo "$DATE - No tomcat process found. Running bin/startup.sh" >&2 | ||
$TOMCAT_DIR/bin/startup.sh | ||
exit 1 | ||
else | ||
echo "$DATE - PID $PID, tomcat still running"; | ||
fi | ||
|
||
echo "pid: $PID" | ||
|
||
STATUS=`curl --connect-timeout 15 --write-out %{http_code} -silent http://localhost:8080/legislation/bill/S1234-2011 | tail -1` | ||
|
||
echo "http status: $STATUS" | ||
|
||
# Here we consider 20 seconds to be unresponsive. | ||
# It is important to ping :8080 directly instead of going through the proxy | ||
# because the proxy (aka varnish) might be having problems or be in the middle | ||
# of reloading. | ||
STATUS=`curl --connect-timeout 20 --write-out %{http_code} --silent http://open.nysenate.gov:8080/legislation/bill/S1234-2011 | tail -1` | ||
if [ $STATUS -ne "200" ]; then | ||
echo "$DATE - tomcat was unresponsive.. restarting" >&2 | ||
kill -9 $PID | ||
bin/startup.sh | ||
sleep 10 | ||
echo `curl --write-out %{http_code} http://localhost:8080/legislation/bill/S1234-2011` >&2 | ||
exit 1 | ||
echo "$DATE - HTTP $STATUS, restarting tomcat" >&2 | ||
# Sometimes bin/shutdown.sh won't work. We need to be sure. | ||
kill -9 $PID | ||
$TOMCAT_DIR/bin/startup.sh | ||
# TODO: Why are we sleeping here? | ||
sleep 10 | ||
exit 1 | ||
else | ||
echo "$DATE - HTTP $STATUS, checkup detected no issues." >&2 | ||
fi | ||
|
||
echo "no problems in tomcat land" | ||
|
||
exit 0 | ||
|