head 1.1; access; symbols; locks georg:1.1; strict; comment @# @; 1.1 date 2003.06.28.19.54.05; author georg; state Exp; branches; next ; desc @@ 1.1 log @Initial revision @ text @#!/usr/bin/env python import re,time import os,stat import sys versionid="$Id: sp-watchdog,v 1.2 2002/11/24 15:31:53 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) @