[ start | index | login ]
start > Virtual Brain > Linux > Tomcat Monitoring

Tomcat Monitoring

Created by stefan. Last edited by stefan, 6 years and 266 days ago. Viewed 681 times. #4
[diff] [history] [edit] [rdf]
labels
attachments
A simple shell script that monitors / supervises my Tomcat process and restarts it if it can not be reached.

Note:

  • It does not access the proc-filesystem of Linux. This would be another feasible approach.
  • The script is to be run on the same machine as the start-script for Tomcat.
  • And finally: It's suitable to supervise a webserver as well, it doesn't have to be Tomcat.
#!/bin/bash

#-------------------------------------------------------- # Script contacts a HTTP-Server and executes # a command if server seems to be down. #--------------------------------------------------------

# # Definitions on checked target # SERVER=localhost PORT=8080 URL=/index.jsp CONTENT="HTTP/1.1 200 OK" START_CMD=/usr/java/tomcat/bin/startup.sh RESTART_LOG=/var/log/tomcat/tomcat-restart.log RESTART_MAILADR=calvin@hobbes.com

# # Contact server and save server's answer # ANSWER=`wget --server-response --output-document=- >>http://$SERVER:$PORT/$URL 2>&1`

# # Parse answer for content # RUNNING=`echo $ANSWER | grep "$CONTENT" | wc -l`

# # React according to running flag # if [ $RUNNING == 1 ] then echo "Server $SERVER:$PORT is running, ok." else DATE_STR=`date` ERR_MSG="$DATE_STR $SERVER:$PORT is NOT running, execute start command..."

# Write notification to log if log file defined if [[ -n "$RESTART_LOG" ]] then echo $ERR_MSG >> $RESTART_LOG fi

# Notify admin via mail if mail address defined if [[ -n "$RESTART_MAILADR" ]] then echo "The server will be restarted. Maybe you want to check >>http://$SERVER:$PORT$URL" | mail -s "$ERR_MSG" $RESTART_MAILADR fi exec $START_CMD fi

no comments | post comment
search www.stefanrufer.ch
Google

Content

Me?


Blog Calendar

< February 2012 >
SunMonTueWedThuFriSat
1234
567891011
12131415161718
19202122232425
26272829

Weblog summary 2007, 2006, 2005, 2004


Content managed by SnipSnap

M

snipsnap.org | Copyright 2000-2002 Matthias L. Jugel and Stephan J. Schmidt