hi,

A while ago someone was asking about monitoring zope. This is a simple
python script I use to keep an eye on the server.

It's run in cron, every so often it fetches the last known zope PID, and
makes sure zope is still running on it.  If it's not, it runs the Zope
startup script.

I'll eventual improve upon it so it mails me a note and makes a log so I
know if zope starts to bail quite a bit.

j.

......................
..... Jason C. Leach
... University College of the Cariboo.
.. 
#!/usr/local/bin/python
#
# Simple Zope monitoring script.
# Jason C. Leach. Canada.
#


import string, os

def ScanLines(token, command):
    #print 'in ScanLines'

    Status = 0

    # fetch data
    Lines = PipeInput(command)

    # cycle through the input
    for line in Lines:
        # if a line contains the 'daemons' name, just exit gracefully.
        Status = string.find(line, token)
        #print Status
        #print line
        # should exit
        if Status >= 0:
            Status = 1
            break
        else:
            Status = 0

    #print 'done ScanLines'
    return Status

def PipeInput(command):
    # check to make sure the disks are not to full.
    #print 'int PipeInput'

    # variable decleration
    Lines = []

    # open pipe to os command
    pipe = os.popen(command, 'r')

    # fetch input
    Lines = pipe.readlines()

    # close the pipe
    pipe.close()

    return Lines
    
def GetPid(FILE):
    
    fin = open(FILE, 'r')
    
    pid = fin.readline()
    
    fin.close()
    
    return pid
    
    
    
if __name__ == '__main__':
    
    TOKEN = 'Zope'
    ZOPEPID = '/usr/local/www/Zope/var/zProcessManager.pid'
    CMD = 'ps -p ' + GetPid(ZOPEPID) + ' | grep Zope'
    SCRIPT = ' /usr/local/etc/rc.d/zope.sh start'
    
    
    
    Status = ScanLines(TOKEN, CMD)
    if not Status:
        os.system(SCRIPT)
    
    #return 1
        

Reply via email to