ia64/xen-unstable

changeset 12788:565cd8f32c70

Close the server when instructed, so that we can reload on the same port, and
diagnose a server that fails to start.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author Ewan Mellor <ewan@xensource.com>
date Mon Dec 04 13:57:18 2006 +0000 (2006-12-04)
parents 3629873ee1e6
children c7f4a89eb054
files tools/python/xen/xend/server/XMLRPCServer.py
line diff
     1.1 --- a/tools/python/xen/xend/server/XMLRPCServer.py	Mon Dec 04 13:56:27 2006 +0000
     1.2 +++ b/tools/python/xen/xend/server/XMLRPCServer.py	Mon Dec 04 13:57:18 2006 +0000
     1.3 @@ -16,6 +16,8 @@
     1.4  # Copyright (C) 2006 XenSource Ltd.
     1.5  #============================================================================
     1.6  
     1.7 +import errno
     1.8 +import socket
     1.9  import types
    1.10  import xmlrpclib
    1.11  from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
    1.12 @@ -105,20 +107,25 @@ class XMLRPCServer:
    1.13                     "; authentication has been disabled for this server." or
    1.14                     ".")
    1.15  
    1.16 -        if self.use_tcp:
    1.17 -            log.info("Opening TCP XML-RPC server on %s%d%s",
    1.18 -                     self.host and '%s:' % self.host or
    1.19 -                     'all interfaces, port ',
    1.20 -                     self.port, authmsg)
    1.21 -            self.server = TCPXMLRPCServer((self.host, self.port),
    1.22 -                                          self.hosts_allowed,
    1.23 -                                          logRequests = False)
    1.24 -        else:
    1.25 -            log.info("Opening Unix domain socket XML-RPC server on %s%s",
    1.26 -                     self.path, authmsg)
    1.27 -            self.server = UnixXMLRPCServer(self.path, self.hosts_allowed,
    1.28 -                                           logRequests = False)
    1.29 -
    1.30 +        try:
    1.31 +            if self.use_tcp:
    1.32 +                log.info("Opening TCP XML-RPC server on %s%d%s",
    1.33 +                         self.host and '%s:' % self.host or
    1.34 +                         'all interfaces, port ',
    1.35 +                         self.port, authmsg)
    1.36 +                self.server = TCPXMLRPCServer((self.host, self.port),
    1.37 +                                              self.hosts_allowed,
    1.38 +                                              logRequests = False)
    1.39 +            else:
    1.40 +                log.info("Opening Unix domain socket XML-RPC server on %s%s",
    1.41 +                         self.path, authmsg)
    1.42 +                self.server = UnixXMLRPCServer(self.path, self.hosts_allowed,
    1.43 +                                               logRequests = False)
    1.44 +        except socket.error, exn:
    1.45 +            log.error('Cannot start server: %s!', exn.args[1])
    1.46 +            ready = True
    1.47 +            running = False
    1.48 +            return
    1.49  
    1.50          # Register Xen API Functions
    1.51          # -------------------------------------------------------------------
    1.52 @@ -177,6 +184,11 @@ class XMLRPCServer:
    1.53  
    1.54      def cleanup(self):
    1.55          log.debug("XMLRPCServer.cleanup()")
    1.56 +        try:
    1.57 +            self.server.socket.close()
    1.58 +        except Exception, exn:
    1.59 +            log.exception(exn)
    1.60 +            pass
    1.61  
    1.62      def shutdown(self):
    1.63          self.running = False