#!/usr/bin/python """Script to verify that the basic observatory services are running To be installed as a cron job for regular checking every 10 minutes. (see man cron)""" # Copyright 2005, 2006 EIAO Consoritum # This program is distributed under the terms of the GNU General # Public License. # # This file is part of the European Internet Accessibility Observatory # (EIAO) # # EIAO is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # EIAO is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with EIAO; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, # MA 02110-1301 USA import os import time import socket import SOAPpy import timeoutsocket timeoutsocket.setDefaultSocketTimeout(120) import sc import urllib sc=sc.SystemConfiguration() htmltest="""
"""
def servicecheck(servicename):
try:
pid=file("/var/run/"+servicename+".pid").read()
except IOError,e:
# Restart the service
print "Restarting ",servicename
os.system("/etc/init.d/"+servicename+" start")
return
try:
os.stat("/proc/"+pid)
except OSError,e:
# Restart the service
print "Restarting ",servicename
os.system("/etc/init.d/"+servicename+" start")
# Give the WAM some time to start up and accept connections
time.sleep(10)
return
def sanitycheck(servicename):
# Perform a sanity check of the WAM, and restart it if it fails the
# sanity check.
# sc.wamservers
for serverurl in sc.wamservers.split(','):
serverurl = urllib.unquote(serverurl)
server = SOAPpy.SOAPProxy(serverurl)
ctype="text/html"
charset='utf-8'
try:
content=unicode(htmltest, charset)
except UnicodeDecodeError:
content=unicode(htmltest, 'iso-8859-1')
try:
earl = server.check("http://www.example.org",content,ctype,charset,ruleset="all",httpheader={})
except (timeoutsocket.Timeout,socket.error):
earl = None
if earl in ("None",None):
print "WAM appears not to work properly, restarting."
os.system("/etc/init.d/"+servicename+" stop")
# Sleep for 60 seconds to let server terminate before attempting to
# start a new server.
time.sleep(60)
os.system("/etc/init.d/"+servicename+" start")
servicecheck("relaxedwam")
sanitycheck("relaxedwam")