head 1.2; access; symbols; locks georg:1.2; strict; comment @# @; 1.2 date 2002.11.24.15.31.53; author georg; state Exp; branches; next 1.1; 1.1 date 2002.11.24.15.27.25; author georg; state Exp; branches; next ; desc @first version, crashes when image not there @ 1.2 log @catch os.stat exception when image is missing @ text @#!/usr/bin/env python import re,time import os,stat import sys versionid="$Id:$" 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) @ 1.1 log @Initial revision @ text @d7 1 d25 4 a28 1 age=time.time()-os.stat(path)[stat.ST_MTIME] @