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

[Xen-changelog] [xen-unstable] Added rudimentary "xend reload" functionality. This allows you to reconfigure



# HG changeset patch
# User Ewan Mellor <ewan@xxxxxxxxxxxxx>
# Node ID 59f438d2739bd53162e81f3213b620b7212be892
# Parent  56d93b6ea9eab9ea044acdbae647a569fe20def8
Added rudimentary "xend reload" functionality.  This allows you to reconfigure
the services offered by Xend, without restarting the daemon itself.

Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx>
---
 tools/examples/init.d/xend                |    5 -
 tools/misc/xend                           |    4 
 tools/python/xen/xend/server/SrvDaemon.py |    8 +
 tools/python/xen/xend/server/SrvServer.py |  125 +++++++++++++++++-------------
 4 files changed, 89 insertions(+), 53 deletions(-)

diff -r 56d93b6ea9ea -r 59f438d2739b tools/examples/init.d/xend
--- a/tools/examples/init.d/xend        Mon Dec 04 10:27:23 2006 +0000
+++ b/tools/examples/init.d/xend        Mon Dec 04 13:37:53 2006 +0000
@@ -36,7 +36,10 @@ case "$1" in
   status)
        xend status
        ;;
-  restart|reload|force-reload)
+  reload)
+        xend reload
+        ;;
+  restart|force-reload)
        xend restart
        await_daemons_up
        ;;
diff -r 56d93b6ea9ea -r 59f438d2739b tools/misc/xend
--- a/tools/misc/xend   Mon Dec 04 10:27:23 2006 +0000
+++ b/tools/misc/xend   Mon Dec 04 13:37:53 2006 +0000
@@ -109,7 +109,7 @@ def main():
     
     daemon = SrvDaemon.instance()
     if not sys.argv[1:]:
-        print 'usage: %s {start|stop|restart}' % sys.argv[0]
+        print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
     elif sys.argv[1] == 'start':
         if os.uname()[0] != "SunOS":
             start_xenstored()
@@ -123,6 +123,8 @@ def main():
         return daemon.start(trace=1)
     elif sys.argv[1] == 'stop':
         return daemon.stop()
+    elif sys.argv[1] == 'reload':
+        return daemon.reloadConfig()
     elif sys.argv[1] == 'restart':
         start_xenstored()
         start_consoled()
diff -r 56d93b6ea9ea -r 59f438d2739b tools/python/xen/xend/server/SrvDaemon.py
--- a/tools/python/xen/xend/server/SrvDaemon.py Mon Dec 04 10:27:23 2006 +0000
+++ b/tools/python/xen/xend/server/SrvDaemon.py Mon Dec 04 13:37:53 2006 +0000
@@ -58,6 +58,14 @@ class Daemon:
         if running == 0 and os.path.isfile(XEND_PID_FILE):
             os.remove(XEND_PID_FILE)
         return running
+
+
+    def reloadConfig(self):
+        """
+        """
+        pid = read_pid(XEND_PID_FILE)
+        if find_process(pid, XEND_PROCESS_NAME):
+            os.kill(pid, signal.SIGHUP)
 
 
     def status(self):
diff -r 56d93b6ea9ea -r 59f438d2739b tools/python/xen/xend/server/SrvServer.py
--- a/tools/python/xen/xend/server/SrvServer.py Mon Dec 04 10:27:23 2006 +0000
+++ b/tools/python/xen/xend/server/SrvServer.py Mon Dec 04 13:37:53 2006 +0000
@@ -65,6 +65,7 @@ class XendServers:
     def __init__(self):
         self.servers = []
         self.cleaningUp = False
+        self.reloadingConfig = False
 
     def add(self, server):
         self.servers.append(server)
@@ -78,6 +79,11 @@ class XendServers:
             except:
                 pass
 
+    def reloadConfig(self, signum = 0, frame = None):
+        log.debug("SrvServer.reloadConfig()")
+        self.reloadingConfig = True
+        self.cleanup(signum, frame)
+
     def start(self, status):
         # Running the network script will spawn another process, which takes
         # the status fd with it unless we set FD_CLOEXEC.  Failing to do this
@@ -86,61 +92,71 @@ class XendServers:
             fcntl.fcntl(status, fcntl.F_SETFD, fcntl.FD_CLOEXEC)
         
         Vifctl.network('start')
-        threads = []
-        for server in self.servers:
-            thread = Thread(target=server.run, name=server.__class__.__name__)
-            if isinstance(server, HttpServer):
-                thread.setDaemon(True)
-            thread.start()
-            threads.append(thread)
-
-
-        # check for when all threads have initialized themselves and then
-        # close the status pipe
-
-        threads_left = True
-        while threads_left:
-            threads_left = False
-
-            for server in self.servers:
-                if not server.ready:
-                    threads_left = True
-                    break
-
-            if threads_left:
-                time.sleep(.5)
-
-        if status:
-            status.write('0')
-            status.close()
 
         # Prepare to catch SIGTERM (received when 'xend stop' is executed)
         # and call each server's cleanup if possible
         signal.signal(signal.SIGTERM, self.cleanup)
-
-        # Interruptible Thread.join - Python Bug #1167930
-        #   Replaces: for t in threads: t.join()
-        #   Reason:   The above will cause python signal handlers to be
-        #             blocked so we're not able to catch SIGTERM in any
-        #             way for cleanup
-        runningThreads = threads
-        while len(runningThreads) > 0:
-            try:
-                for t in threads:
-                    t.join(1.0)
-                runningThreads = [t for t in threads
-                                  if t.isAlive() and not t.isDaemon()]
-                if self.cleaningUp and len(runningThreads) > 0:
-                    log.debug("Waiting for %s." %
-                              [x.getName() for x in runningThreads])
-            except:
-                pass
-
-
-def create():
-    root = SrvDir()
-    root.putChild('xend', SrvRoot())
-    servers = XendServers()
+        signal.signal(signal.SIGHUP, self.reloadConfig)
+
+        while True:
+            threads = []
+            for server in self.servers:
+                thread = Thread(target=server.run, 
name=server.__class__.__name__)
+                if isinstance(server, HttpServer):
+                    thread.setDaemon(True)
+                thread.start()
+                threads.append(thread)
+
+
+            # check for when all threads have initialized themselves and then
+            # close the status pipe
+
+            threads_left = True
+            while threads_left:
+                threads_left = False
+
+                for server in self.servers:
+                    if not server.ready:
+                        threads_left = True
+                        break
+
+                if threads_left:
+                    time.sleep(.5)
+
+            if status:
+                status.write('0')
+                status.close()
+                status = None
+
+            # Interruptible Thread.join - Python Bug #1167930
+            #   Replaces: for t in threads: t.join()
+            #   Reason:   The above will cause python signal handlers to be
+            #             blocked so we're not able to catch SIGTERM in any
+            #             way for cleanup
+            runningThreads = threads
+            while len(runningThreads) > 0:
+                try:
+                    for t in threads:
+                        t.join(1.0)
+                    runningThreads = [t for t in threads
+                                      if t.isAlive() and not t.isDaemon()]
+                    if self.cleaningUp and len(runningThreads) > 0:
+                        log.debug("Waiting for %s." %
+                                  [x.getName() for x in runningThreads])
+                except:
+                    pass
+
+            if self.reloadingConfig:
+                log.info("Restarting all servers...")
+                self.cleaningUp = False
+                self.reloadingConfig = False
+                xroot.set_config()
+                self.servers = []
+                _loadConfig(self)
+            else:
+                break
+
+def _loadConfig(servers):
     if xroot.get_xend_http_server():
         servers.add(HttpServer(root,
                                xroot.get_xend_address(),
@@ -188,4 +204,11 @@ def create():
 
     if xroot.get_xend_unix_xmlrpc_server():
         servers.add(XMLRPCServer(XendAPI.AUTH_PAM))
+
+
+def create():
+    root = SrvDir()
+    root.putChild('xend', SrvRoot())
+    servers = XendServers()
+    _loadConfig(servers)
     return servers

_______________________________________________
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®.