#!/usr/bin/env python import re,time import os,stat import sys versionid="$Id: sp-watchdog,v 1.1 2003/06/28 19:54:05 georg Exp georg $" configfile="/usr/local/etc/sunpendulum.conf" restartcommand="svc -k /service/sp-server" true=1 re_in=re.compile(r".*?(\d+)(\s*|\s+#.*)$") re_path=re.compile(r".*?(\S+)(\s*|\s+#.*)$") f=open(configfile) for i in f.readlines(): if i.lower().startswith("web_dump_interval"): interval=int(re_in.match(i).group(1)) if i.lower().startswith("web_dump_path"): path=re_path.match(i).group(1) sys.stdout.write ( "Startup: watching %s with interval %d seconds.\n" % (path,interval)) sys.stdout.flush() while true: try: age=time.time()-os.stat(path)[stat.ST_MTIME] except: age=interval*2 if age > interval*1.5: sys.stdout.write ( "KILLING, age is %f\n" % age) sys.stdout.flush() os.system (restartcommand) time.sleep(interval) time.sleep(interval/3.0)