[CalendarServer-changes] [4366] CalendarServer/trunk/contrib/migration/59_calendarmigrator.py
source_changes at macosforge.org
source_changes at macosforge.org
Mon Jun 22 15:41:50 PDT 2009
Revision: 4366
http://trac.macosforge.org/projects/calendarserver/changeset/4366
Author: sagen at apple.com
Date: 2009-06-22 15:41:49 -0700 (Mon, 22 Jun 2009)
Log Message:
-----------
During migration/upgrade, don't actually start calendar server -- just update its launchd settings so that it will start after the post-upgrade reboot.
Modified Paths:
--------------
CalendarServer/trunk/contrib/migration/59_calendarmigrator.py
Modified: CalendarServer/trunk/contrib/migration/59_calendarmigrator.py
===================================================================
--- CalendarServer/trunk/contrib/migration/59_calendarmigrator.py 2009-06-22 19:08:51 UTC (rev 4365)
+++ CalendarServer/trunk/contrib/migration/59_calendarmigrator.py 2009-06-22 22:41:49 UTC (rev 4366)
@@ -34,7 +34,6 @@
LAUNCHD_OVERRIDES = "var/db/launchd.db/com.apple.launchd/overrides.plist"
LAUNCHD_PREFS_DIR = "System/Library/LaunchDaemons"
CALDAVD_CONFIG_DIR = "private/etc/caldavd"
-SERVERADMIN = "/usr/sbin/serveradmin"
def main():
@@ -81,7 +80,7 @@
def migrateRunState(options):
"""
Try to determine whether server was running in previous system, then
- user serveradmin to start/stop the server in the new system.
+ modify the launchd settings in the new system.
"""
try:
@@ -93,27 +92,9 @@
(LAUNCHD_KEY, e))
return
- command = "stop" if disabled else "start"
- try:
- processArgs = [SERVERADMIN, command, SERVICE_NAME]
- log("Invoking %s" % (processArgs,))
- serveradmin = subprocess.Popen(
- args=processArgs,
- stdout=subprocess.PIPE,
- )
- output, error = serveradmin.communicate()
+ setServiceStateDisabled(options.targetRoot, LAUNCHD_KEY, disabled)
- expectedState = "STOPPED" if disabled else "RUNNING"
- if '%s:state = "%s"' % (SERVICE_NAME, expectedState) in output:
- log("Service %s is now %s" % (SERVICE_NAME, expectedState))
- else:
- log("ERROR: serveradmin returned %s" % (output,))
- except Exception, e:
- log("ERROR: Failed to run %s: %s" %
- (SERVERADMIN, e))
-
-
def migrateConfiguration(options):
"""
Copy files/directories/symlinks from previous system's /etc/caldavd
@@ -246,6 +227,24 @@
(overridesPath, prefsPath))
+def setServiceStateDisabled(target, service, disabled):
+ """
+ Modifies launchd settings for a service
+
+ @param target: System root
+ @param service: launchd key representing service
+ @param disabled: boolean
+ """
+
+ overridesPath = os.path.join(target, LAUNCHD_OVERRIDES)
+ if os.path.isfile(overridesPath):
+ overrides = plistlib.readPlist(overridesPath)
+ if not overrides.has_key(service):
+ overrides[service] = { }
+ overrides[service]['Disabled'] = disabled
+ plistlib.writePlist(overrides, overridesPath)
+
+
class ServiceStateError(Exception):
"""
Could not determine service state
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090622/232742f5/attachment.html>
More information about the calendarserver-changes
mailing list