<rdf:RDF
    xmlns:s='http://snipsnap.org/rdf/snip-schema#'
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    xml:base='http://www.stefanrufer.ch/snipsnap/rdf'>
    <s:Snip rdf:about='http://www.stefanrufer.ch/snipsnap/rdf#Virtual+Brain/Linux/Tomcat+Monitoring'
         s:cUser='stefan'
         s:oUser='stefan'
         s:mUser='stefan'>
        <s:name>Virtual Brain/Linux/Tomcat Monitoring</s:name>
        <s:content>A simple shell script that monitors / supervises my Tomcat process and restarts it if it can not be reached. &#xD;&#xA;&#xD;&#xA;Note:&#xD;&#xA; - It does not access the proc-filesystem of Linux. This would be another feasible approach.&#xD;&#xA; - The script is to be run on the same machine as the start-script for Tomcat. &#xD;&#xA; - And finally: It&apos;s suitable to supervise a webserver as well, it doesn&apos;t have to be Tomcat.&#xD;&#xA;&#xD;&#xA;{code:none}&#xD;&#xA;#!/bin/bash&#xD;&#xA;&#xD;&#xA;#--------------------------------------------------------&#xD;&#xA;# Script contacts a HTTP-Server and executes&#xD;&#xA;# a command if server seems to be down.&#xD;&#xA;#--------------------------------------------------------&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;#&#xD;&#xA;# Definitions on checked target&#xD;&#xA;#&#xD;&#xA;SERVER=localhost&#xD;&#xA;PORT=8080&#xD;&#xA;URL=/index.jsp&#xD;&#xA;CONTENT=&quot;HTTP/1.1 200 OK&quot;&#xD;&#xA;START_CMD=/usr/java/tomcat/bin/startup.sh&#xD;&#xA;RESTART_LOG=/var/log/tomcat/tomcat-restart.log&#xD;&#xA;RESTART_MAILADR=calvin@hobbes.com&#xD;&#xA;&#xD;&#xA;&#xD;&#xA;#&#xD;&#xA;# Contact server and save server&apos;s answer&#xD;&#xA;#&#xD;&#xA;ANSWER=`wget --server-response --output-document=- http://$SERVER:$PORT/$URL 2&gt;&amp;1`&#xD;&#xA;&#xD;&#xA;#&#xD;&#xA;# Parse answer for content &#xD;&#xA;#&#xD;&#xA;RUNNING=`echo $ANSWER | grep &quot;$CONTENT&quot; | wc -l`&#xD;&#xA;&#xD;&#xA;#&#xD;&#xA;# React according to running flag&#xD;&#xA;#&#xD;&#xA;if [ $RUNNING == 1 ]&#xD;&#xA;then&#xD;&#xA;  echo &quot;Server $SERVER:$PORT is running, ok.&quot;&#xD;&#xA;else&#xD;&#xA;  DATE_STR=`date`&#xD;&#xA;  ERR_MSG=&quot;$DATE_STR $SERVER:$PORT is NOT running, execute start command...&quot;&#xD;&#xA;&#xD;&#xA;  # Write notification to log if log file defined&#xD;&#xA;  if [[ -n &quot;$RESTART_LOG&quot; ]]&#xD;&#xA;  then&#xD;&#xA;    echo $ERR_MSG &gt;&gt; $RESTART_LOG&#xD;&#xA;  fi&#xD;&#xA;&#xD;&#xA;  # Notify admin via mail if mail address defined&#xD;&#xA;  if [[ -n &quot;$RESTART_MAILADR&quot; ]]&#xD;&#xA;  then&#xD;&#xA;    echo &quot;The server will be restarted. Maybe you want to check http://$SERVER:$PORT$URL&quot; | mail -s &quot;$ERR_MSG&quot; $RESTART_MAILADR&#xD;&#xA;  fi&#xD;&#xA;  exec $START_CMD&#xD;&#xA;fi&#xD;&#xA;{code}&#xD;&#xA;</s:content>
        <s:mTime>2005-05-19 23:08:06.511</s:mTime>
        <s:cTime>2005-04-20 22:57:35.547</s:cTime>
        <s:comments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
        <s:snipLinks>
            <rdf:Bag>
                <rdf:li rdf:resource='#snipsnap-index'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#Virtual Brain'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#Virtual Brain/Linux'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#Virtual+Brain/Linux'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#Virtual+Brain'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#Virtual%2bBrain/Linux/Tomcat%2bMonitoring'/>
                <rdf:li rdf:resource='http://www.stefanrufer.ch/snipsnap/rdf#stefan/SnipSnap Things'/>
            </rdf:Bag>
        </s:snipLinks>
        <s:attachments
             rdf:type='http://www.w3.org/1999/02/22-rdf-syntax-ns#Bag'/>
    </s:Snip>
</rdf:RDF>

