Log in |
Build a Zope health monitorIs 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:
Description: 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:
#!/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> |