ovs-monitor-ipsec: Add unixctl support.
authorEthan Jackson <ethan@nicira.com>
Sat, 3 Mar 2012 02:33:48 +0000 (18:33 -0800)
committerEthan Jackson <ethan@nicira.com>
Fri, 9 Mar 2012 21:37:39 +0000 (13:37 -0800)
With this patch, users can query a running ovs-monitor-ipsec
daemon's version, or ask it to exit using ovs-appctl.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
debian/ovs-monitor-ipsec

index 981f0a2c820a729c85a04a3e997d2cd48db7139c..e89e70922d9f6d069323b94c58b8a40b7b178f73 100755 (executable)
@@ -37,11 +37,19 @@ from ovs.db import types
 import ovs.util
 import ovs.daemon
 import ovs.db.idl
+import ovs.unixctl
 import ovs.vlog
 
 vlog = ovs.vlog.Vlog("ovs-monitor-ipsec")
 root_prefix = ''                # Prefix for absolute file names, for testing.
 setkey = "/usr/sbin/setkey"
+exiting = False
+
+
+def unixctl_exit(conn, unused_argv, unused_aux):
+    global exiting
+    exiting = True
+    conn.reply(None)
 
 
 # Class to configure the racoon daemon, which handles IKE negotiation
@@ -447,12 +455,22 @@ def main():
 
     ovs.daemon.daemonize()
 
+    ovs.unixctl.command_register("exit", "", 0, 0, unixctl_exit, None)
+    error, unixctl_server = ovs.unixctl.UnixctlServer.create(None)
+    if error:
+        ovs.util.ovs_fatal(error, "could not create unixctl server", vlog)
+
     ipsec = IPsec()
 
     interfaces = {}
     while True:
+        unixctl_server.run()
+        if exiting:
+            break
+
         if not idl.run():
             poller = ovs.poller.Poller()
+            unixctl_server.wait(poller)
             idl.wait(poller)
             poller.block()
             continue
@@ -499,6 +517,9 @@ def main():
             update_ipsec(ipsec, interfaces, new_interfaces)
             interfaces = new_interfaces
 
+    unixctl_server.close()
+    idl.close()
+
 
 if __name__ == '__main__':
     try: