[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] Close the server when instructed, so that we can reload on the same port, and



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Node ID 565cd8f32c70da8ae7dbaaeb9dff28aa8b6307e1
# Parent  3629873ee1e607f8e803ba674c387e7850757269
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@xxxxxxxxxxxxx>
---
 tools/python/xen/xend/server/XMLRPCServer.py |   40 +++++++++++++++++----------
 1 files changed, 26 insertions(+), 14 deletions(-)

diff -r 3629873ee1e6 -r 565cd8f32c70 
tools/python/xen/xend/server/XMLRPCServer.py
--- a/tools/python/xen/xend/server/XMLRPCServer.py      Mon Dec 04 13:56:27 
2006 +0000
+++ b/tools/python/xen/xend/server/XMLRPCServer.py      Mon Dec 04 13:57:18 
2006 +0000
@@ -16,6 +16,8 @@
 # Copyright (C) 2006 XenSource Ltd.
 #============================================================================
 
+import errno
+import socket
 import types
 import xmlrpclib
 from xen.util.xmlrpclib2 import UnixXMLRPCServer, TCPXMLRPCServer
@@ -105,20 +107,25 @@ class XMLRPCServer:
                    "; authentication has been disabled for this server." or
                    ".")
 
-        if self.use_tcp:
-            log.info("Opening TCP XML-RPC server on %s%d%s",
-                     self.host and '%s:' % self.host or
-                     'all interfaces, port ',
-                     self.port, authmsg)
-            self.server = TCPXMLRPCServer((self.host, self.port),
-                                          self.hosts_allowed,
-                                          logRequests = False)
-        else:
-            log.info("Opening Unix domain socket XML-RPC server on %s%s",
-                     self.path, authmsg)
-            self.server = UnixXMLRPCServer(self.path, self.hosts_allowed,
-                                           logRequests = False)
-
+        try:
+            if self.use_tcp:
+                log.info("Opening TCP XML-RPC server on %s%d%s",
+                         self.host and '%s:' % self.host or
+                         'all interfaces, port ',
+                         self.port, authmsg)
+                self.server = TCPXMLRPCServer((self.host, self.port),
+                                              self.hosts_allowed,
+                                              logRequests = False)
+            else:
+                log.info("Opening Unix domain socket XML-RPC server on %s%s",
+                         self.path, authmsg)
+                self.server = UnixXMLRPCServer(self.path, self.hosts_allowed,
+                                               logRequests = False)
+        except socket.error, exn:
+            log.error('Cannot start server: %s!', exn.args[1])
+            ready = True
+            running = False
+            return
 
         # Register Xen API Functions
         # -------------------------------------------------------------------
@@ -177,6 +184,11 @@ class XMLRPCServer:
 
     def cleanup(self):
         log.debug("XMLRPCServer.cleanup()")
+        try:
+            self.server.socket.close()
+        except Exception, exn:
+            log.exception(exn)
+            pass
 
     def shutdown(self):
         self.running = False

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.