[ovs-dev] [PATCH 2/3] xenserver: monitor-external-ids respond to SIGHUP

Ethan Jackson ethan at nicira.com
Fri Sep 17 23:21:12 UTC 2010


When monitor-external-ids receives a SIGHUP it will forget
everything and run as if it was newly started.
---
 ..._share_openvswitch_scripts_monitor-external-ids |   26 +++++++++++++++++--
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/xenserver/usr_share_openvswitch_scripts_monitor-external-ids b/xenserver/usr_share_openvswitch_scripts_monitor-external-ids
index a0aad7a..d947940 100755
--- a/xenserver/usr_share_openvswitch_scripts_monitor-external-ids
+++ b/xenserver/usr_share_openvswitch_scripts_monitor-external-ids
@@ -22,6 +22,7 @@
 
 import getopt
 import os
+import signal
 import subprocess
 import sys
 import syslog
@@ -34,9 +35,11 @@ from ovs.db import types
 import ovs.util
 import ovs.daemon
 import ovs.db.idl
+import ovs.timeval
 
 vsctl="/usr/bin/ovs-vsctl"
 session = None
+force_run = False
 
 # Set up a session to interact with XAPI.
 #
@@ -163,8 +166,15 @@ def usage():
     print "Other options:"
     print "  -h, --help               display this help message"
     sys.exit(0)
- 
+
+def handler(signum, frame):
+    global force_run
+    if (signum == signal.SIGHUP):
+        force_run = True
+
 def main(argv):
+    global force_run
+
     try:
         options, args = getopt.gnu_getopt(
             argv[1:], 'h', ['help'] + ovs.daemon.LONG_OPTIONS)
@@ -196,16 +206,26 @@ def main(argv):
     # tasks, we need it.  Wait here until it's up.
     while not os.path.exists("/var/run/xapi_init_complete.cookie"):
         time.sleep(1)
+
+    signal.signal(signal.SIGHUP, handler)
  
     bridges = {}
     interfaces = {}
     while True:
-        if not idl.run():
+        if not force_run and not idl.run():
             poller = ovs.poller.Poller()
             idl.wait(poller)
+
+            # Check if handler has set force_run in the last second
+            poller.timer_wait_until(ovs.timeval.msec() + 1000)
             poller.block()
             continue
- 
+
+        if force_run:
+            bridges    = {}
+            interfaces = {}
+            force_run = False
+
         new_bridges = {}
         for rec in idl.data["Bridge"].itervalues():
             name = rec.name.as_scalar()
-- 
1.7.2.3





More information about the dev mailing list