You are not logged in Log in Join
You are here: Home » Members » Jace's Zope Adventures » Build a Zope health monitor

Log in
Name

Password

 

Build a Zope health monitor

Is your Zope site going down every once in a while? Here is how you can put together a Zope health monitor that automatically restarts Zope and also notifies you, if Zope is found dead.

Prerequisites:
/usr/local/zope must be sym-linked to wherever Zope is installed. I use the binary tarball, so it points to /usr/local/Zope-2.1.6-linux2-x86 on my system. wget must be installed and available in the path. ZServer is assumed to be running on port 8080, with Zap serving up front. A directory named logsnap must exist under Zope's var directory. This will be used for taking snapshots of the logs.

Description:
This script runs out of crontab every one minute and tries to retrieve a test page from ZServer. If it doesn't get a response within 5 seconds, Zope is assumed to be dead and therefore restarted. The script avoids restarting Zope repeatedly if it takes more than a minute to restart. We check Zope on port 8080 instead of Zap, to avoid messing with Zap's logs. Your marketing folks probably depend upon those logs for their jobs.

Cutting script code from a HTML page can be bothersome, so I've included everything in a HTML comment below. Do a View Source on this page.

Files:
The script: /usr/local/zope/zopecheck.sh:

#!/bin/sh
if (wget http://www.zdnetindia.com:8080/statusPage \
--spider -t 1 -T 5 >& /dev/null) ; then
  # Zope is alive
  if [ -f /usr/local/zope/zope-status.down ] ; then
    echo Zope is up | mail you@yourdomain.com
    rm -f /usr/local/zope/zope-status.down
    touch /usr/local/zope/zope-status.up
    echo `date` Zope is up >> /usr/local/zope/crash.log
  fi
else 
  # Zope is dead
  if [ -f /usr/local/zope/zope-status.up ] ; then
    echo Zope is down | mail you@yourdomain.com
    rm -f /usr/local/zope/zope-status.up
    touch /usr/local/zope/zope-status.down
    echo `date` Zope is down >> /usr/local/zope/crash.log
    cd /usr/local/zope
    ./stop
    export DIRNAME="var/logsnap/`date +%Y-%m-%d-%H-%M-%S`"
    mkdir "$DIRNAME"
    tail Zap/logs/zdnetindia.com-access_log > "$DIRNAME/zap.log"
    tail var/Z2.log > "$DIRNAME/Z2.log"
    tail var/debug.log > "$DIRNAME/debug.log"
    tail -30 var/zope-events.log > "$DIRNAME/zope-events.log"
    ./start
  fi
fi

The modified start script:
#! /bin/sh
reldir=`dirname $0`
PYTHONHOME=`cd $reldir; pwd`
export PYTHONHOME
rm -f /usr/local/zope/zope-status.up
touch /usr/local/zope/zope-status.down
exec /usr/local/Zope-2.1.6-linux2-x86/bin/python \
     $PYTHONHOME/z2.py \
     -a "your-IP-address-if-needed" \
     -p /usr/local/zope/Zap/sites/zdnetindia/cgi-bin/Zope.cgi \
     -m "8081" \
     -w 8080 \
     STUPID_LOG_FILE="$PYTHONHOME/var/zope-events.log" \
     "$@"

/etc/crontab entry:
0-59 * * * * root killall zopecheck.sh; /usr/local/zope/zopecheck.sh

/statusPage dummy DTML Method within Zope:
<HTML><HEAD><TITLE>Status Page</TITLE></HEAD>
<BODY><P>Zope is up!</P></BODY></HTML>