WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] Added rudimentary "xend reload" functiona

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] Added rudimentary "xend reload" functionality. This allows you to reconfigure
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Mon, 04 Dec 2006 21:50:14 +0000
Delivery-date: Mon, 04 Dec 2006 13:49:49 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# 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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] Added rudimentary "xend reload" functionality. This allows you to reconfigure, Xen patchbot-unstable <=