summaryrefslogtreecommitdiffstats
path: root/src/lib
diff options
context:
space:
mode:
authorNarayan Desai <desai@mcs.anl.gov>2009-06-23 01:56:08 +0000
committerNarayan Desai <desai@mcs.anl.gov>2009-06-23 01:56:08 +0000
commit7139c9cd7ea4a1d13323d4add72f87a0bd3f293f (patch)
tree9f647d67e1cfe3b1011cf5e1d0e276398d04046b /src/lib
parent940f209fae2491f42daf34b7bfb0fd052316c955 (diff)
downloadbcfg2-7139c9cd7ea4a1d13323d4add72f87a0bd3f293f.tar.gz
bcfg2-7139c9cd7ea4a1d13323d4add72f87a0bd3f293f.tar.bz2
bcfg2-7139c9cd7ea4a1d13323d4add72f87a0bd3f293f.zip
Improve server error handling
Issues - Log bind failures properly - Log ssl key/cert/ca key existence problems git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@5294 ce84e21b-d406-0410-9b95-82705330c041
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/Component.py11
-rw-r--r--src/lib/SSLServer.py23
2 files changed, 28 insertions, 6 deletions
diff --git a/src/lib/Component.py b/src/lib/Component.py
index 9449d3df7..b3f8a0941 100644
--- a/src/lib/Component.py
+++ b/src/lib/Component.py
@@ -18,6 +18,8 @@ import Bcfg2.Logger
from Bcfg2.Statistics import Statistics
from Bcfg2.SSLServer import XMLRPCServer
+logger = logging.getLogger()
+
class NoExposedMethod (Exception):
"""There is no method exposed with the given name."""
@@ -59,9 +61,12 @@ def run_component (component_cls, location, daemon, pidfile_name, argv=None,
up = urlparse.urlparse(location)
port = tuple(up[1].split(':'))
port = (port[0], int(port[1]))
-
- server = XMLRPCServer(port, keyfile=keyfile, certfile=certfile,
- register=register, timeout=time_out, ca=ca)
+ try:
+ server = XMLRPCServer(port, keyfile=keyfile, certfile=certfile,
+ register=register, timeout=time_out, ca=ca)
+ except:
+ logger.error("Server startup failed")
+ os._exit(1)
server.register_instance(component)
try:
diff --git a/src/lib/SSLServer.py b/src/lib/SSLServer.py
index 891636eb1..90007cbb9 100644
--- a/src/lib/SSLServer.py
+++ b/src/lib/SSLServer.py
@@ -6,6 +6,7 @@ __all__ = [
"SSLServer", "XMLRPCRequestHandler", "XMLRPCServer",
]
+import os
import sys
import xmlrpclib
import socket
@@ -89,13 +90,29 @@ class SSLServer (SocketServer.TCPServer, object):
"""
all_iface_address = ('', server_address[1])
- SocketServer.TCPServer.__init__(self, all_iface_address,
- RequestHandlerClass)
+ try:
+ SocketServer.TCPServer.__init__(self, all_iface_address,
+ RequestHandlerClass)
+ except socket.error:
+ self.logger.error("Failed to bind to socket")
+ raise
self.socket.settimeout(timeout)
self.keyfile = keyfile
+ if keyfile != None:
+ if not os.path.exists(keyfile):
+ self.logger.error("Keyfile %s does not exist" % keyfile)
+ raise Exception, "keyfile doesn't exist"
self.certfile = certfile
+ if certfile != None:
+ if not os.path.exists(certfile):
+ self.logger.error("Certfile %s does not exist" % certfile)
+ raise Exception, "certfile doesn't exist"
self.ca = ca
+ if ca != None:
+ if not os.path.exists(ca):
+ self.logger.error("CA %s does not exist" % ca)
+ raise Exception, "ca doesn't exist"
self.reqCert = reqCert
if ca and certfile:
self.mode = ssl.CERT_OPTIONAL
@@ -255,7 +272,6 @@ class XMLRPCServer (SocketServer.ThreadingMixIn, SSLServer,
self.register = register
self.register_introspection_functions()
self.register_function(self.ping)
- self.task_thread = threading.Thread(target=self._tasks_thread)
self.logger.info("service available at %s" % self.url)
self.timeout = timeout
@@ -301,6 +317,7 @@ class XMLRPCServer (SocketServer.ThreadingMixIn, SSLServer,
def serve_forever (self):
"""Serve single requests until (self.serve == False)."""
self.serve = True
+ self.task_thread = threading.Thread(target=self._tasks_thread)
self.task_thread.start()
self.logger.info("serve_forever() [start]")
signal.signal(signal.SIGINT, self._handle_shutdown_signal)