]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2582] Let the msgq connect to itself
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 15 Jan 2013 11:43:50 +0000 (12:43 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Tue, 15 Jan 2013 11:43:50 +0000 (12:43 +0100)
Once the config manager is ready, connect to itself to get the config.
Not covered by unit tests, since it is part of startup routine and
requires interaction with other modules, but lettuce succeeds, which
means msgq itself works.

src/bin/msgq/Makefile.am
src/bin/msgq/msgq.py.in
src/bin/msgq/msgq.spec [new file with mode: 0644]

index 5f377b1eef8d6a33a183b15b74ac2319e7b26f7d..a49b125e1852a6d91da5f9989feda04b0300f1bb 100644 (file)
@@ -4,13 +4,16 @@ pkglibexecdir = $(libexecdir)/@PACKAGE@
 
 pkglibexec_SCRIPTS = b10-msgq
 
+b10_msgqdir = $(pkgdatadir)
+b10_msgq_DATA = msgq.spec
+
 CLEANFILES = b10-msgq msgq.pyc
 CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/work/msgq_messages.py
 CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/work/msgq_messages.pyc
 
 man_MANS = b10-msgq.8
 DISTCLEANFILES = $(man_MANS)
-EXTRA_DIST = $(man_MANS) msgq.xml msgq_messages.mes
+EXTRA_DIST = $(man_MANS) msgq.xml msgq_messages.mes msgq.spec
 
 nodist_pylogmessage_PYTHON = $(PYTHON_LOGMSGPKG_DIR)/work/msgq_messages.py
 pylogmessagedir = $(pyexecdir)/isc/log_messages/
index ef1fe8888f8a4b42c17209b1037bebf166dd4d42..efbe197aae835e4ffad295d9478a2cb021545a68 100755 (executable)
@@ -30,6 +30,7 @@ import time
 import select
 import random
 import threading
+import isc.config.ccsession
 from optparse import OptionParser, OptionValueError
 import isc.util.process
 import isc.log
@@ -38,6 +39,8 @@ from isc.log_messages.msgq_messages import *
 import isc.cc
 
 isc.util.process.rename()
+
+isc.log.init("b10-msgq")
 # Logger that is used in the actual msgq handling - startup, shutdown and the
 # poller thread.
 logger = isc.log.Logger("msgq")
@@ -54,6 +57,17 @@ TRACE_DETAIL = logger.DBGLVL_TRACE_DETAIL
 # number, and the overall BIND 10 version number (set in configure.ac).
 VERSION = "b10-msgq 20110127 (BIND 10 @PACKAGE_VERSION@)"
 
+# If B10_FROM_BUILD is set in the environment, we use data files
+# from a directory relative to that, otherwise we use the ones
+# installed on the system
+if "B10_FROM_BUILD" in os.environ:
+    SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/msgq"
+else:
+    PREFIX = "@prefix@"
+    DATAROOTDIR = "@datarootdir@"
+    SPECFILE_PATH = "@datadir@/@PACKAGE@".replace("${datarootdir}", DATAROOTDIR).replace("${prefix}", PREFIX)
+SPECFILE_LOCATION = SPECFILE_PATH + "/msgq.spec"
+
 class MsgQReceiveError(Exception): pass
 
 class SubscriptionManager:
@@ -630,6 +644,18 @@ class MsgQ:
         if os.path.exists(self.socket_file):
             os.remove(self.socket_file)
 
+    def config_handler(self, new_config):
+        """The configuration handler (run in a separate thread).
+           Not tested, currently effectively empty.
+        """
+        return isc.config.create_answer(0)
+
+    def command_handler(self, command, args):
+        """The command handler (run in a separate thread).
+           Not tested, currently effectively empty.
+        """
+        return isc.config.create_answer(1, 'unknown command: ' + command)
+
 # can signal handling and calling a destructor be done without a
 # global variable?
 msgq = None
@@ -649,6 +675,7 @@ if __name__ == "__main__":
 
     # Parse any command-line options.
     parser = OptionParser(version=VERSION)
+    # TODO: Should we remove the option?
     parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
                       help="display more about what is going on")
     parser.add_option("-s", "--socket-file", dest="msgq_socket_file",
@@ -656,14 +683,6 @@ if __name__ == "__main__":
                       help="UNIX domain socket file the msgq daemon will use")
     (options, args) = parser.parse_args()
 
-    # Init logging, according to the parameters.
-    # FIXME: Do proper logger configuration, this is just a hack
-    # This is #2582
-    sev = 'INFO'
-    if options.verbose:
-        sev = 'DEBUG'
-    isc.log.init("b10-msgq", buffer=False, severity=sev, debuglevel=99)
-
     signal.signal(signal.SIGTERM, signal_handler)
 
     # Announce startup.
@@ -685,6 +704,15 @@ if __name__ == "__main__":
     poller_thread.daemon = True
     try:
         poller_thread.start()
+        if msgq.wait_cfgmgr():
+            # Once we get the config manager, we can read our own config.
+            session = isc.config.ModuleCCSession(SPECFILE_LOCATION,
+                                                 msgq.config_handler,
+                                                 msgq.command_handler,
+                                                 None, True,
+                                                 msgq.socket_file)
+            session.start()
+            # TODO: Background the session loop
         poller_thread.join()
     except KeyboardInterrupt:
         pass
diff --git a/src/bin/msgq/msgq.spec b/src/bin/msgq/msgq.spec
new file mode 100644 (file)
index 0000000..93204fa
--- /dev/null
@@ -0,0 +1,8 @@
+{
+  "module_spec": {
+    "module_name": "Msgq",
+    "module_description": "The message queue",
+    "config_data": [],
+    "commands": []
+  }
+}