diff --git a/fail2ban b/fail2ban index abc9f9e2..f904271d 100755 --- a/fail2ban +++ b/fail2ban @@ -26,22 +26,28 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -from sys import exit, path +import sys, traceback, logging -# Appends our own modules path. Added before log4py import -# because log4py could be distributed with Fail2Ban. -path.append("/usr/lib/fail2ban") +# Appends our own modules path. +sys.path.append("/usr/lib/fail2ban") -# Checks for required libs -# Checks if log4py is present. -try: - import log4py -except: - print "log4py is needed (see README)" - exit(-1) - -# Now we can import our module +# Now we can import our module. import fail2ban -# Start the application -fail2ban.main() +# Gets the instance of the logger. +logSys = logging.getLogger("fail2ban") + +# Start the application. Handle all the unhandled exceptions +try: + fail2ban.main() +except SystemExit: + # We called sys.exit(). Nothing wrong so just pass + pass +except Exception, e: + (type, value, tb) = sys.exc_info() + tbStack = traceback.extract_tb(tb) + logSys.error("Fail2Ban got an unhandled exception and died.") + logSys.error("Type: " + `type.__name__` + "\n" + + "Value: " + `e.args` + "\n" + + "TB: " + `tbStack`) + logging.shutdown()