[CalendarServer-changes] [15483] CalendarServer/trunk/calendarserver/tap

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 22 17:29:51 PDT 2016


Revision: 15483
          http://trac.calendarserver.org//changeset/15483
Author:   sagen at apple.com
Date:     2016-03-22 17:29:51 -0700 (Tue, 22 Mar 2016)
Log Message:
-----------
Wait for server root to become available prior to finishing reading config.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tap/caldav.py
    CalendarServer/trunk/calendarserver/tap/util.py

Modified: CalendarServer/trunk/calendarserver/tap/caldav.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/caldav.py	2016-03-22 22:31:11 UTC (rev 15482)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py	2016-03-23 00:29:51 UTC (rev 15483)
@@ -24,7 +24,7 @@
 
 import sys
 from collections import OrderedDict
-from os import getuid, getgid, umask, remove, environ, stat, chown, W_OK
+from os import getuid, getgid, geteuid, umask, remove, environ, stat, chown, W_OK
 from os.path import exists, basename
 import socket
 from stat import S_ISSOCK
@@ -74,6 +74,7 @@
 from twext.application.service import ReExecService
 from txdav.who.groups import GroupCacherPollingWork
 from calendarserver.tools.purge import PrincipalPurgePollingWork
+from calendarserver.tools.util import checkDirectory
 
 from txweb2.channel.http import (
     LimitingHTTPFactory, SSLRedirectRequest, HTTPChannel
@@ -119,6 +120,7 @@
     pgServiceFromConfig, getDBPool, MemoryLimitService,
     storeFromConfig, getSSLPassphrase, preFlightChecks,
     storeFromConfigWithDPSClient, storeFromConfigWithoutDPS,
+    serverRootLocation
 )
 try:
     from calendarserver.version import version
@@ -405,6 +407,8 @@
 
     def postOptions(self):
         try:
+            if geteuid() == 0:
+                self.waitForServerRoot()
             self.loadConfiguration()
             self.checkConfiguration()
         except ConfigurationError, e:
@@ -412,6 +416,20 @@
             sys.exit(1)
 
 
+    def waitForServerRoot(self):
+        """
+        Block until server root directory is available
+        """
+        serverRootPath = serverRootLocation()
+        if serverRootPath:
+            checkDirectory(
+                serverRootPath,
+                "Server root",
+                access=W_OK,
+                wait=True  # Wait in a loop until ServerRoot exists
+            )
+
+
     def loadConfiguration(self):
         if not exists(self["config"]):
             raise ConfigurationError(

Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py	2016-03-22 22:31:11 UTC (rev 15482)
+++ CalendarServer/trunk/calendarserver/tap/util.py	2016-03-23 00:29:51 UTC (rev 15483)
@@ -103,6 +103,7 @@
 from txweb2.resource import Resource
 from txweb2.static import File as FileResource
 
+from plistlib import readPlist
 from urllib import quote
 import OpenSSL
 import errno
@@ -111,6 +112,7 @@
 import sys
 import time
 
+
 try:
     from twistedcaldav.authkerb import NegotiateCredentialFactory
     NegotiateCredentialFactory  # pacify pyflakes
@@ -1554,3 +1556,19 @@
                 "Could not post alert: {alertType} {args} ({error})",
                 alertType=alertType, args=args, error=e
             )
+
+
+def serverRootLocation():
+    """
+    Return the ServerRoot value from the OS X preferences plist.  If plist not
+    present, return empty string.
+
+    @rtype: C{unicode}
+    """
+    defaultPlistPath = "/Library/Server/Preferences/Calendar.plist"
+    serverRoot = u""
+    if os.path.exists(defaultPlistPath):
+        serverRoot = readPlist(defaultPlistPath).get("ServerRoot", serverRoot)
+    if isinstance(serverRoot, str):
+        serverRoot = serverRoot.decode("utf-8")
+    return serverRoot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20160322/24a9900d/attachment-0001.html>


More information about the calendarserver-changes mailing list