[CalendarServer-changes] [3533] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Dec 15 13:44:49 PST 2008


Revision: 3533
          http://trac.macosforge.org/projects/calendarserver/changeset/3533
Author:   sagen at apple.com
Date:     2008-12-15 13:44:49 -0800 (Mon, 15 Dec 2008)
Log Message:
-----------
If you specify an empty ControlSocket value in the plist, a TCP socket will be used instead.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/conf/caldavd-test.plist
    CalendarServer/trunk/twistedcaldav/accesslog.py
    CalendarServer/trunk/twistedcaldav/config.py
    CalendarServer/trunk/twistedcaldav/notify.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2008-12-15 21:42:59 UTC (rev 3532)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2008-12-15 21:44:49 UTC (rev 3533)
@@ -601,10 +601,17 @@
             else:
                 realRoot = logWrapper
 
-            logObserver = AMPCommonAccessLoggingObserver(
-                config.ControlSocket,
-            )
+            if config.ControlSocket:
+                mode = "AF_UNIX"
+                id = config.ControlSocket
+                self.log_info("Logging via AF_UNIX: %s" % (id,))
+            else:
+                mode = "IF_INET"
+                id = int(config.ControlPort)
+                self.log_info("Logging via AF_INET: %d" % (id,))
 
+            logObserver = AMPCommonAccessLoggingObserver(mode, id)
+
         elif config.ProcessType == "Single":
             realRoot = logWrapper
 
@@ -703,6 +710,20 @@
 
     def makeService_Combined(self, options):
         s = MultiService()
+
+        # The logger service must come before the monitor service, otherwise
+        # we won't know which logging port to pass to the slaves' command lines
+
+        logger = AMPLoggingFactory(
+            RotatingFileAccessLoggingObserver(config.AccessLogFile)
+        )
+        if config.ControlSocket:
+            loggingService = UNIXServer(config.ControlSocket, logger)
+        else:
+            loggingService = ControlPortTCPServer(config.ControlPort, logger,
+                interface="127.0.0.1")
+        loggingService.setServiceParent(s)
+
         monitor = DelayedStartupProcessMonitor()
         monitor.setServiceParent(s)
         s.processMonitor = monitor
@@ -792,11 +813,7 @@
                 sslPort
             )
 
-            monitor.addProcess(
-                process.getName(),
-                process.getCommandLine(),
-                env=parentEnv
-            )
+            monitor.addProcessObject(process, parentEnv)
 
             if config.HTTPPort:
                 hosts.append(process.getHostLine())
@@ -923,11 +940,8 @@
                 "-n", "caldav_notifier",
                 "-f", options["config"],
             ]
-            monitor.addProcess(
-                "notifications",
-                notificationsArgv,
-                env=parentEnv,
-            )
+            monitor.addProcess("notifications", notificationsArgv,
+                env=parentEnv)
 
         if (
             config.Scheduling.iMIP.Enabled and
@@ -944,14 +958,6 @@
             monitor.addProcess("mailgateway", mailGatewayArgv, env=parentEnv)
 
 
-        logger = AMPLoggingFactory(
-            RotatingFileAccessLoggingObserver(config.AccessLogFile)
-        )
-
-        loggingService = UNIXServer(config.ControlSocket, logger)
-
-        loggingService.setServiceParent(s)
-
         return s
 
     def makeService_Master(self, options):
@@ -974,7 +980,6 @@
 
         return service
 
-
 class TwistdSlaveProcess(object):
     prefix = "caldav"
 
@@ -1025,7 +1030,9 @@
             "-o", "PIDFile=None",
             "-o", "ErrorLogFile=None",
             "-o", "MultiProcess/ProcessCount=%d"
-                  % (config.MultiProcess.ProcessCount,)
+                  % (config.MultiProcess.ProcessCount,),
+            "-o", "ControlPort=%d"
+                  % (config.ControlPort,),
         ])
 
         if config.Memcached.ServerEnabled:
@@ -1059,11 +1066,42 @@
         return """<host name="%s" ip="127.0.0.1:%s" />""" % (name, port[0])
 
 
+class ControlPortTCPServer(TCPServer):
+    """ This TCPServer retrieves the port number that was actually assigned
+        when the service was started, and stores that into config.ControlPort
+    """
+
+    def startService(self):
+        TCPServer.startService(self)
+        # Record the port we were actually assigned
+        config.ControlPort = self._port.getHost().port
+
 class DelayedStartupProcessMonitor(procmon.ProcessMonitor):
+
+    def __init__(self, *args, **kwargs):
+        procmon.ProcessMonitor.__init__(self, *args, **kwargs)
+
+        # processObjects stores TwistdSlaveProcesses which need to have their
+        # command-lines determined just in time
+        self.processObjects = []
+
+    def addProcessObject(self, process, env):
+        self.processObjects.append((process, env))
+
     def startService(self):
         Service.startService(self)
+
+        # Now we're ready to build the command lines and actualy add the
+        # processes to procmon.  This step must be done prior to setting
+        # active to 1
+        for processObject, env in self.processObjects:
+            self.addProcess(
+                processObject.getName(),
+                processObject.getCommandLine(),
+                env=env
+            )
+
         self.active = 1
-
         delay = 0
 
         if config.MultiProcess.StaggeredStartup.Enabled:

Modified: CalendarServer/trunk/conf/caldavd-test.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-test.plist	2008-12-15 21:42:59 UTC (rev 3532)
+++ CalendarServer/trunk/conf/caldavd-test.plist	2008-12-15 21:44:49 UTC (rev 3533)
@@ -609,7 +609,8 @@
     <key>ResponseCompression</key>
     <false/>
 
-    <!-- A unix socket used for communication between the child and master processes. -->
+    <!-- A unix socket used for communication between the child and master processes.
+         An empty value tells the server to use a tcp socket instead. -->
     <key>ControlSocket</key>
     <string>logs/caldavd.sock</string>
 

Modified: CalendarServer/trunk/twistedcaldav/accesslog.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/accesslog.py	2008-12-15 21:42:59 UTC (rev 3532)
+++ CalendarServer/trunk/twistedcaldav/accesslog.py	2008-12-15 21:44:49 UTC (rev 3533)
@@ -259,8 +259,9 @@
 
 
 class AMPCommonAccessLoggingObserver(CommonAccessLoggingObserverExtensions):
-    def __init__(self, socket):
-        self.socket = socket
+    def __init__(self, mode, id):
+        self.mode = mode
+        self.id = id
         self.protocol = None
         self._buffer = []
 
@@ -279,7 +280,10 @@
             self.flushBuffer()
 
         self.client = protocol.ClientCreator(reactor, amp.AMP)
-        d = self.client.connectUNIX(self.socket)
+        if self.mode == "AF_UNIX":
+            d = self.client.connectUNIX(self.id)
+        else:
+            d = self.client.connectTCP("localhost", self.id)
         d.addCallback(_gotProtocol)
 
     def stop(self):

Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py	2008-12-15 21:42:59 UTC (rev 3532)
+++ CalendarServer/trunk/twistedcaldav/config.py	2008-12-15 21:44:49 UTC (rev 3533)
@@ -365,10 +365,15 @@
     # Umask
     "umask": 0027,
 
+    # A TCP port used for communication between the child and master
+    # processes (bound to 127.0.0.1). Specify 0 to let OS assign a port.
+    "ControlPort": 0,
+
     # A unix socket used for communication between the child and master
-    # processes.
+    # processes. If blank, then an AF_INET socket is used instead.
     "ControlSocket": "/var/run/caldavd.sock",
 
+
     # Support for Content-Encoding compression options as specified in
     # RFC2616 Section 3.5
     "ResponseCompression": True,

Modified: CalendarServer/trunk/twistedcaldav/notify.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/notify.py	2008-12-15 21:42:59 UTC (rev 3532)
+++ CalendarServer/trunk/twistedcaldav/notify.py	2008-12-15 21:44:49 UTC (rev 3533)
@@ -652,9 +652,6 @@
     def publishNodeFailure(self, result, nodeName):
         try:
             iq = result.value.getElement()
-            self.log_error("PubSub node publish error: %s" %
-                (iq.toXml().encode('ascii', 'replace')),)
-            self.sendDebug("Node publish failed (%s)" % (nodeName,), iq)
 
             if iq.name == "error":
                 if iq['code'] == '400':
@@ -663,6 +660,9 @@
                 elif iq['code'] == '404':
                     self.createNode(nodeName)
             else:
+                self.log_error("PubSub node publish error: %s" %
+                    (iq.toXml().encode('ascii', 'replace')),)
+                self.sendDebug("Node publish failed (%s)" % (nodeName,), iq)
                 # Don't know how to proceed
                 self.unlockNode(None, nodeName)
         except:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081215/aac9bf81/attachment-0001.html>


More information about the calendarserver-changes mailing list