From 820b2a677475e26aa29a23cd9c4eadcaf4ec4730 Mon Sep 17 00:00:00 2001 From: Narayan Desai Date: Thu, 23 Nov 2006 14:18:31 +0000 Subject: Fixup server error handling * Remove ssl key print * Handle bind failure case cleanly git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2533 ce84e21b-d406-0410-9b95-82705330c041 --- src/lib/Server/Component.py | 4 +++- src/sbin/bcfg2-server | 11 +++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lib/Server/Component.py b/src/lib/Server/Component.py index f3bd47d34..ecb476780 100644 --- a/src/lib/Server/Component.py +++ b/src/lib/Server/Component.py @@ -53,7 +53,6 @@ class SSLServer(BaseHTTPServer.HTTPServer): def __init__(self, address, keyfile, handler): SocketServer.BaseServer.__init__(self, address, handler) ctxt = OpenSSL.SSL.Context(OpenSSL.SSL.SSLv23_METHOD) - print keyfile ctxt.use_privatekey_file (keyfile) ctxt.use_certificate_file(keyfile) #ctxt.load_verify_locations('/tmp/keys/CA.cert') @@ -134,6 +133,9 @@ class Component(SSLServer, try: SSLServer.__init__(self, location, keyfile, CobaltXMLRPCRequestHandler) + except socket.error: + self.logger.error("Failed to bind to socket") + raise ComponentInitError except: self.logger.error("Failed to load ssl key %s" % (keyfile), exc_info=1) raise ComponentInitError diff --git a/src/sbin/bcfg2-server b/src/sbin/bcfg2-server index c6d3d9ab7..4204b49ba 100755 --- a/src/sbin/bcfg2-server +++ b/src/sbin/bcfg2-server @@ -59,6 +59,10 @@ def critical_error(operation): logger.error(operation, exc_info=1) raise Fault, (7, "Critical unexpected failure: %s" % (operation)) +class SetupError(Exception): + '''Used when the server cant be setup''' + pass + class Bcfg2Serv(Bcfg2.Server.Component.Component): """The Bcfg2 Server component providing XML-RPC access to Bcfg methods""" __name__ = 'bcfg2' @@ -71,8 +75,7 @@ class Bcfg2Serv(Bcfg2.Server.Component.Component): Bcfg2.Server.Component.Component.__init__(self, setup) self.shut = False except Bcfg2.Server.Component.ComponentInitError: - logger.critical("Failed to setup server") - raise SystemExit, 1 + raise SetupError # set shutdown handlers for sigint and sigterm signal.signal(signal.SIGINT, self.start_shutdown) @@ -216,8 +219,8 @@ if __name__ == '__main__': daemonize(SSETUP['daemon']) try: BSERV = Bcfg2Serv(SSETUP) - except: - critical_error("Failed to setup server; probably a key problem") + except SetupError: + raise SystemExit, 1 while not BSERV.shut: try: BSERV.serve_forever() -- cgit v1.2.3-1-g7c22