def _quitHandler(signum, frame): """ Cleanly shuts down this daemon upon receipt of a SIGTERM. @type signum: int @param signum: The kill-signal constant received. This will always be SIGTERM. @type frame: int @param frame: The stack-frame in which the kill-signal was received. This is not used. """ #Remove PID. try: os.unlink(conf.PID_FILE) except: pass logging.logToDisk() exit(0)
def _logHandler(signum, frame): """ Flushes DHCP cache and writes log to disk upon receipt of a SIGHUP. @type signum: int @param signum: The kill-signal constant received. This will always be SIGHUP. @type frame: int @param frame: The stack-frame in which the kill-signal was received. This is not used. """ dhcp.flushCache() if not logging.logToDisk(): logging.writeLog("Unable to write logfile: %(log)s" % {'log': conf.LOG_FILE,}) else: logging.writeLog("Wrote log to '%(log)s'" % {'log': conf.LOG_FILE,})
def do_POST(self): """ Handles all HTTP POST requests. This checks to see if the user entered the flush key and, if so, flushes the cache and writes the memory-log to disk. """ try: (ctype, pdict) = cgi.parse_header(self.headers.getheader('content-type')) if ctype == 'application/x-www-form-urlencoded': query = parse_qs(self.rfile.read(int(self.headers.getheader('content-length')))) key = query.get('key') if key: if hashlib.md5(key[0]).hexdigest() == conf.WEB_RELOAD_KEY: dhcp.flushCache() if logging.logToDisk(): logging.writeLog("Wrote log to '%(log)s'" % {'log': conf.LOG_FILE,}) else: logging.writeLog("Unable to write log to '%(log)s'" % {'log': conf.LOG_FILE,}) else: logging.writeLog("Invalid Web-access-key provided") except Exception, e: logging.writeLog("Problem while processing POST in Web module: %(error)s" % {'error': str(e),})