Python, Service dies but PID remains.. Log file updates every minute -


i have service topic says dies , leave stale pid behind. particular service logs every minute. want create python script check logfile based on modified time, if file has not updated in 3 minutes restart service.

i new scripting / programming need logic here please...

this have far check on file age.

#!/usr/bin/python import os, datetime, time  os import path datetime import datetime, timedelta #file = "/var/log/file.log"  def check_file(seconds, file_name):      try:         time_diff  = datetime.now() - timedelta(seconds)         file_time = datetime.fromtimestamp(path.getctime(file_name))         if file_time < time_diff:             return [true, "file: %s. older than: %s, file_time:%s , date_diff:%s " % (file_name, seconds, file_time, time_diff)]         else:             return [true, "file: %s. older than: %s, file_time:%s , date_diff:%s " % (file_name, seconds, file_time, time_diff)]      except exception, e:         return [false, e] 

before writing custom code handle problem (and having 2 problems), i'd at:

  1. fixing service doesn't die,

  2. adding monitoring service @ box level (see this example).

if these options not practical, start bash based solution on python.

in either case, you'll need make sure restarting script doesn't die either.


Comments