[CalendarServer-changes] [10005] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Tue Nov 6 14:01:58 PST 2012
Revision: 10005
http://trac.calendarserver.org//changeset/10005
Author: sagen at apple.com
Date: 2012-11-06 14:01:57 -0800 (Tue, 06 Nov 2012)
Log Message:
-----------
Split calendar/contacts data out from shared Postgres to our own
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tap/util.py
CalendarServer/trunk/calendarserver/tools/backup_pg.py
CalendarServer/trunk/conf/caldavd-apple.plist
CalendarServer/trunk/contrib/migration/calendarmigrator.py
CalendarServer/trunk/contrib/migration/calendarpromotion.py
CalendarServer/trunk/contrib/migration/test/test_migrator.py
CalendarServer/trunk/contrib/migration/test/test_promotion.py
CalendarServer/trunk/support/Makefile.Apple
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/txdav/base/datastore/subpostgres.py
CalendarServer/trunk/txdav/base/datastore/test/test_subpostgres.py
Added Paths:
-----------
CalendarServer/trunk/contrib/migration/calendarcommonextra.py
CalendarServer/trunk/lib-patches/pycrypto/
CalendarServer/trunk/lib-patches/pycrypto/__init__.py.patch
CalendarServer/trunk/txdav/base/datastore/test/importFile.sql
Removed Paths:
-------------
CalendarServer/trunk/contrib/create_caldavd_db.sh
Modified: CalendarServer/trunk/calendarserver/tap/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tap/util.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/calendarserver/tap/util.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -131,7 +131,8 @@
maxConnections=config.Postgres.MaxConnections,
options=config.Postgres.Options,
uid=uid, gid=gid,
- spawnedDBUser=config.SpawnedDBUser
+ spawnedDBUser=config.SpawnedDBUser,
+ importFileName=config.DBImportFile
)
Modified: CalendarServer/trunk/calendarserver/tools/backup_pg.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/backup_pg.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/calendarserver/tools/backup_pg.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -112,7 +112,7 @@
print e.output
raise BackupError(
"%s failed:\n%s (exit code = %d)" %
- (PGDUMP, e.output, e.returncode)
+ (PSQL, e.output, e.returncode)
)
Modified: CalendarServer/trunk/conf/caldavd-apple.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-apple.plist 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/conf/caldavd-apple.plist 2012-11-06 22:01:57 UTC (rev 10005)
@@ -96,9 +96,11 @@
<!-- Database connection -->
<key>DBType</key>
- <string>postgres</string>
+ <string></string>
<key>DSN</key>
- <string>/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::</string>
+ <string></string>
+ <key>DBImportFile</key>
+ <string>/Library/Server/Calendar and Contacts/DataDump.sql</string>
<!-- Data root -->
<key>DataRoot</key>
Deleted: CalendarServer/trunk/contrib/create_caldavd_db.sh
===================================================================
--- CalendarServer/trunk/contrib/create_caldavd_db.sh 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/contrib/create_caldavd_db.sh 2012-11-06 22:01:57 UTC (rev 10005)
@@ -1,5 +0,0 @@
-#!/usr/bin/env bash
-
-/Applications/Server.app/Contents/ServerRoot/usr/sbin/calendarserver_bootstrap_database
-
-exit 0
Added: CalendarServer/trunk/contrib/migration/calendarcommonextra.py
===================================================================
--- CalendarServer/trunk/contrib/migration/calendarcommonextra.py (rev 0)
+++ CalendarServer/trunk/contrib/migration/calendarcommonextra.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -0,0 +1,122 @@
+#!/usr/bin/env python
+#
+# CommonExtra script for calendar server.
+#
+# Copyright (c) 2012 Apple Inc. All Rights Reserved.
+#
+# IMPORTANT NOTE: This file is licensed only for use on Apple-labeled
+# computers and is subject to the terms and conditions of the Apple
+# Software License Agreement accompanying the package this file is a
+# part of. You may not port this file to another platform without
+# Apple's written consent.
+
+
+# NOTES:
+# - Start the "postgres for server" instance
+# - See if there is calendar/contacts data
+# - pgdump to a file within DataRoot
+# - Drop the database within "postgres for server" instance
+# - Start our service (if needed)
+
+import datetime
+import subprocess
+
+LOG = "/Library/Logs/Migration/calendarmigrator.log"
+SERVER_APP_ROOT = "/Applications/Server.app/Contents/ServerRoot"
+CALENDAR_SERVER_ROOT = "/Library/Server/Calendar and Contacts"
+SERVER_ADMIN = "%s/usr/sbin/serveradmin" % (SERVER_APP_ROOT,)
+PGDUMP = "%s/usr/bin/pg_dump" % (SERVER_APP_ROOT,)
+DROPDB = "%s/usr/bin/dropdb" % (SERVER_APP_ROOT,)
+POSTGRES_SERVICE_NAME = "postgres_server"
+PGSOCKETDIR = "/Library/Server/PostgreSQL For Server Services/Socket"
+USERNAME = "caldav"
+DATABASENAME = "caldav"
+DATADUMPFILENAME = "%s/DataDump.sql" % (CALENDAR_SERVER_ROOT,)
+
+def log(msg):
+ try:
+ timestamp = datetime.datetime.now().strftime("%b %d %H:%M:%S")
+ msg = "calendarcommonextra: %s %s" % (timestamp, msg)
+ print msg # so it appears in Setup.log
+ with open(LOG, 'a') as output:
+ output.write("%s\n" % (msg,)) # so it appears in our log
+ except IOError:
+ # Could not write to log
+ pass
+
+
+def startPostgres():
+ """
+ Start postgres via serveradmin
+
+ This will block until postgres is up and running
+ """
+ log("Starting %s via %s" % (POSTGRES_SERVICE_NAME, SERVER_ADMIN))
+ ret = subprocess.call([SERVER_ADMIN, "start", POSTGRES_SERVICE_NAME])
+ log("serveradmin exited with %d" % (ret,))
+
+def stopPostgres():
+ """
+ Stop postgres via serveradmin
+ """
+ log("Stopping %s via %s" % (POSTGRES_SERVICE_NAME, SERVER_ADMIN))
+ ret = subprocess.call([SERVER_ADMIN, "stop", POSTGRES_SERVICE_NAME])
+ log("serveradmin exited with %d" % (ret,))
+
+
+def dumpOldDatabase(dumpFile):
+ """
+ Use pg_dump to dump data to dumpFile
+ """
+
+ cmdArgs = [
+ PGDUMP,
+ "-h", PGSOCKETDIR,
+ "--username=%s" % (USERNAME,),
+ "--inserts",
+ "--no-privileges",
+ "--file=%s" % (dumpFile,),
+ DATABASENAME
+ ]
+ try:
+ log("Dumping data to %s" % (dumpFile,))
+ log("Executing: %s" % (" ".join(cmdArgs)))
+ out = subprocess.check_output(cmdArgs, stderr=subprocess.STDOUT)
+ log(out)
+ return True
+ except subprocess.CalledProcessError, e:
+ log(e.output)
+ return False
+
+
+def dropOldDatabase():
+ """
+ Use dropdb to delete the caldav database from the shared postgres server
+ """
+
+ cmdArgs = [
+ DROPDB,
+ "-h", PGSOCKETDIR,
+ "--username=%s" % (USERNAME,),
+ DATABASENAME
+ ]
+ try:
+ log("\nDropping %s database" % (DATABASENAME,))
+ log("Executing: %s" % (" ".join(cmdArgs)))
+ out = subprocess.check_output(cmdArgs, stderr=subprocess.STDOUT)
+ log(out)
+ return True
+ except subprocess.CalledProcessError, e:
+ log(e.output)
+ return False
+
+
+def main():
+ startPostgres()
+ if dumpOldDatabase(DATADUMPFILENAME):
+ dropOldDatabase()
+ stopPostgres()
+
+
+if __name__ == "__main__":
+ main()
Modified: CalendarServer/trunk/contrib/migration/calendarmigrator.py
===================================================================
--- CalendarServer/trunk/contrib/migration/calendarmigrator.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/contrib/migration/calendarmigrator.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -169,8 +169,13 @@
# Trigger migration of locations and resources from OD
triggerResourceMigration(newServerRoot)
- setRunState(options, enableCalDAV, enableCardDAV)
+ # TODO: instead of starting now, leave breadcrumbs for
+ # the commonextra to start the service, so that data can
+ # be dumped from the old Postgres to a file which will
+ # be executed by calendar server when it next starts up.
+ # setRunState(options, enableCalDAV, enableCardDAV)
+
else:
log("ERROR: --sourceRoot and --sourceVersion must be specified")
sys.exit(1)
@@ -479,9 +484,15 @@
# If SSL is enabled, redirect HTTP to HTTPS.
combined["RedirectHTTPToHTTPS"] = enableSSL
- # New DSN value for server-specific Postgres
- combined["DSN"] = "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::"
+ # New DBType value indicating we launch our own Postgres
+ combined["DBType"] = ""
+ # No DSN value since we launch our own Postgres
+ combined["DSN"] = ""
+
+ # Path to SQL file to import previous data from
+ combined["DBImportFile"] = "/Library/Server/Calendar and Contacts/DataDump.sql"
+
# ConfigRoot is now always "Config"
combined["ConfigRoot"] = "Config"
Modified: CalendarServer/trunk/contrib/migration/calendarpromotion.py
===================================================================
--- CalendarServer/trunk/contrib/migration/calendarpromotion.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/contrib/migration/calendarpromotion.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -27,8 +27,9 @@
def updatePlist(plistData):
"""
- Update the passed-in plist data with new values for disabling the XMPPNotifier, and
- to set the DSN to use the server-specific Postgres.
+ Update the passed-in plist data with new values for disabling the XMPPNotifier,
+ to set DBType to empty string indicating we'll be starting our own Postgres server,
+ and to specify the new location for ConfigRoot ("Config" directory beneath ServerRoot).
@param plistData: the plist data to update in place
@type plistData: C{dict}
@@ -38,9 +39,13 @@
plistData["Notifications"]["Services"]["XMPPNotifier"]["Enabled"] = False
except KeyError:
pass
- plistData["DSN"] = "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::"
+ plistData["DBType"] = ""
+ plistData["DSN"] = ""
+ plistData["ConfigRoot"] = "Config"
+ plistData["DBImportFile"] = "/Library/Server/Calendar and Contacts/DataDump.sql"
+
def main():
try:
Modified: CalendarServer/trunk/contrib/migration/test/test_migrator.py
===================================================================
--- CalendarServer/trunk/contrib/migration/test/test_migrator.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/contrib/migration/test/test_migrator.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -90,7 +90,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : True,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": True,
@@ -129,7 +131,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -168,7 +172,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : True,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": True,
@@ -207,7 +213,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : True,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": True,
@@ -246,7 +254,9 @@
"BindHTTPPorts": [1111, 2222, 4444, 5555, 7777, 8888],
"BindSSLPorts": [3333, 6666, 9999, 11111],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : True,
"HTTPPort": 8888,
"RedirectHTTPToHTTPS": True,
@@ -282,7 +292,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -313,7 +325,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : True,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": True,
@@ -335,7 +349,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -383,7 +399,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -423,7 +441,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -476,7 +496,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -518,7 +540,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -560,7 +584,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
@@ -596,7 +622,9 @@
"BindHTTPPorts": [8008, 8800],
"BindSSLPorts": [8443, 8843],
"ConfigRoot" : "Config",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DSN" : "",
+ "DBType" : "",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
"EnableSSL" : False,
"HTTPPort": 8008,
"RedirectHTTPToHTTPS": False,
Modified: CalendarServer/trunk/contrib/migration/test/test_promotion.py
===================================================================
--- CalendarServer/trunk/contrib/migration/test/test_promotion.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/contrib/migration/test/test_promotion.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -32,7 +32,10 @@
}
expected = {
"ignored" : "ignored",
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
+ "DBType" : "",
+ "DSN" : "",
+ "ConfigRoot" : "Config",
}
updatePlist(orig)
self.assertEquals(orig, expected)
@@ -44,7 +47,9 @@
"Enabled" : True
}
}
- }
+ },
+ "ConfigRoot" : "/etc/caldavd",
+
}
expected = {
"Notifications" : {
@@ -54,7 +59,10 @@
}
}
},
- "DSN" : "/Library/Server/PostgreSQL For Server Services/Socket:caldav:caldav:::",
+ "DBImportFile" : "/Library/Server/Calendar and Contacts/DataDump.sql",
+ "DBType" : "",
+ "DSN" : "",
+ "ConfigRoot" : "Config",
}
updatePlist(orig)
self.assertEquals(orig, expected)
Added: CalendarServer/trunk/lib-patches/pycrypto/__init__.py.patch
===================================================================
--- CalendarServer/trunk/lib-patches/pycrypto/__init__.py.patch (rev 0)
+++ CalendarServer/trunk/lib-patches/pycrypto/__init__.py.patch 2012-11-06 22:01:57 UTC (rev 10005)
@@ -0,0 +1,6 @@
+Index: lib/Crypto/Random/Fortuna/__init__.py
+===================================================================
+--- lib/Crypto/Random/Fortuna/__init__.py
++++ lib/Crypto/Random/Fortuna/__init__.py
+@@ -0,0 +1 @@
++#
Modified: CalendarServer/trunk/support/Makefile.Apple
===================================================================
--- CalendarServer/trunk/support/Makefile.Apple 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/support/Makefile.Apple 2012-11-06 22:01:57 UTC (rev 10005)
@@ -60,16 +60,17 @@
sqlparse-0.1.2:: $(BuildDirectory)/sqlparse-0.1.2
setproctitle-1.1.6:: $(BuildDirectory)/setproctitle-1.1.6
psutil-0.6.1:: $(BuildDirectory)/psutil-0.6.1
+pycrypto-2.5:: $(BuildDirectory)/pycrypto-2.5
$(Project):: $(BuildDirectory)/$(Project)
-build:: PyKerberos pycalendar PyGreSQL-4.0 sqlparse-0.1.2 setproctitle-1.1.6 psutil-0.6.1 $(Project)
+build:: PyKerberos pycalendar PyGreSQL-4.0 sqlparse-0.1.2 setproctitle-1.1.6 psutil-0.6.1 pycrypto-2.5 $(Project)
setup:
$(_v) ./run -g
-prep:: setup CalDAVTester.tgz PyKerberos.tgz pycalendar.tgz PyGreSQL-4.0.tgz sqlparse-0.1.2.tgz setproctitle-1.1.6.tgz psutil-0.6.1.tgz
+prep:: setup CalDAVTester.tgz PyKerberos.tgz pycalendar.tgz PyGreSQL-4.0.tgz sqlparse-0.1.2.tgz setproctitle-1.1.6.tgz psutil-0.6.1.tgz pycrypto-2.5.tgz
-PyKerberos pycalendar PyGreSQL-4.0 sqlparse-0.1.2 setproctitle-1.1.6 psutil-0.6.1 $(Project)::
+PyKerberos pycalendar PyGreSQL-4.0 sqlparse-0.1.2 setproctitle-1.1.6 psutil-0.6.1 pycrypto-2.5 $(Project)::
@echo "Building $@..."
$(_v) cd $(BuildDirectory)/$@ && $(Environment) $(PYTHON) setup.py build
@@ -81,6 +82,7 @@
$(_v) cd $(BuildDirectory)/sqlparse-0.1.2 && $(Environment) $(PYTHON) setup.py install $(PY_INSTALL_FLAGS)
$(_v) cd $(BuildDirectory)/setproctitle-1.1.6 && $(Environment) $(PYTHON) setup.py install $(PY_INSTALL_FLAGS)
$(_v) cd $(BuildDirectory)/psutil-0.6.1 && $(Environment) $(PYTHON) setup.py install $(PY_INSTALL_FLAGS)
+ $(_v) cd $(BuildDirectory)/pycrypto-2.5 && $(Environment) $(PYTHON) setup.py install $(PY_INSTALL_FLAGS)
$(_v) for so in $$(find "$(DSTROOT)$(PY_HOME)/lib" -type f -name '*.so'); do $(STRIP) -Sx "$${so}"; done
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SIPP)$(ETCDIR)$(CALDAVDSUBDIR)"
$(_v) $(INSTALL_FILE) "$(Sources)/conf/caldavd-apple.plist" "$(DSTROOT)$(SIPP)$(ETCDIR)$(CALDAVDSUBDIR)/caldavd.plist"
@@ -110,23 +112,23 @@
$(_v) $(INSTALL_DIRECTORY) -o "$(CS_USER)" -g "$(CS_GROUP)" -m 0755 "$(DSTROOT)$(VARDIR)/log$(CALDAVDSUBDIR)"
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SIPP)$(NSLIBRARYDIR)/LaunchDaemons"
$(_v) $(INSTALL_FILE) "$(Sources)/contrib/launchd/calendarserver.plist" "$(DSTROOT)$(SIPP)$(NSLIBRARYDIR)/LaunchDaemons/org.calendarserver.calendarserver.plist"
- @echo "Installing migration config..."
+ @echo "Installing migration extras script..."
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/MigrationExtras"
$(_v) $(INSTALL_FILE) "$(Sources)/contrib/migration/calendarmigrator.py" "$(DSTROOT)$(SERVERSETUP)/MigrationExtras/70_calendarmigrator.py"
$(_v) chmod ugo+x "$(DSTROOT)$(SERVERSETUP)/MigrationExtras/70_calendarmigrator.py"
- @echo "Installing server promotion config..."
+ @echo "Installing common extras script..."
+ $(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/CommonExtras"
+ $(_v) $(INSTALL_FILE) "$(Sources)/contrib/migration/calendarcommonextra.py" "$(DSTROOT)$(SERVERSETUP)/CommonExtras/70_calendarcommonextra.py"
+ $(_v) chmod ugo+x "$(DSTROOT)$(SERVERSETUP)/CommonExtras/70_calendarcommonextra.py"
+ @echo "Installing server promotion extras script..."
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/PromotionExtras"
$(_v) $(INSTALL_FILE) "$(Sources)/contrib/migration/calendarpromotion.py" "$(DSTROOT)$(SERVERSETUP)/PromotionExtras/59_calendarpromotion.py"
$(_v) chmod ugo+x "$(DSTROOT)$(SERVERSETUP)/PromotionExtras/59_calendarpromotion.py"
- @echo "Installing server demotion config..."
+ @echo "Installing server uninstall extras script..."
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/UninstallExtras"
$(_v) $(INSTALL_FILE) "$(Sources)/contrib/migration/calendardemotion.py" "$(DSTROOT)$(SERVERSETUP)/UninstallExtras/59_calendardemotion.py"
$(_v) chmod ugo+x "$(DSTROOT)$(SERVERSETUP)/UninstallExtras/59_calendardemotion.py"
- @echo "Installing database configuration scripts..."
- $(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SERVERSETUP)/CommonExtras/PostgreSQLExtras"
- $(_v) $(INSTALL_FILE) "$(Sources)/contrib/create_caldavd_db.sh" "$(DSTROOT)$(SERVERSETUP)/CommonExtras/PostgreSQLExtras/create_caldavd_db.sh"
- $(_v) chmod ugo+x "$(DSTROOT)$(SERVERSETUP)/CommonExtras/PostgreSQLExtras/create_caldavd_db.sh"
- @echo "Installing changeip config..."
+ @echo "Installing changeip script..."
$(_v) $(INSTALL_DIRECTORY) "$(DSTROOT)$(SIPP)$(LIBEXECDIR)/changeip"
$(_v) $(INSTALL_FILE) "$(Sources)/calendarserver/tools/changeip_calendar.py" "$(DSTROOT)$(SIPP)$(LIBEXECDIR)/changeip/changeip_calendar.py"
$(_v) chmod ugo+x "$(DSTROOT)$(SIPP)$(LIBEXECDIR)/changeip/changeip_calendar.py"
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -285,6 +285,8 @@
"SpawnedDBUser" : "caldav", # The username to use when DBType is empty
+ "DBImportFile" : "", # File path to SQL file to import at startup (includes schema)
+
"DSN" : "", # Data Source Name. Used to connect to an external
# database if DBType is non-empty. Format varies
# depending on database type.
Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -165,7 +165,8 @@
maxConnections=20, options=[],
testMode=False,
uid=None, gid=None,
- spawnedDBUser="caldav"):
+ spawnedDBUser="caldav",
+ importFileName=None):
"""
Initialize a L{PostgresService} pointed at a data store directory.
@@ -175,6 +176,11 @@
@param subServiceFactory: a 1-arg callable that will be called with a
1-arg callable which returns a DB-API cursor.
@type subServiceFactory: C{callable}
+
+ @param spawnedDBUser: the postgres role
+ @type spawnedDBUser: C{str}
+ @param importFileName: path to SQL file containing previous data to import
+ @type importFileName: C{str}
"""
# FIXME: By default there is very little (4MB) shared memory available,
@@ -225,6 +231,7 @@
self.uid = uid
self.gid = gid
self.spawnedDBUser = spawnedDBUser
+ self.importFileName = importFileName
self.schema = schema
self.monitor = None
self.openConnections = []
@@ -281,6 +288,8 @@
def ready(self):
"""
Subprocess is ready. Time to initialize the subservice.
+ If the database has not been created and there is a dump file,
+ then the dump file is imported.
"""
createDatabaseConn = self.produceConnection(
'schema creation', 'postgres'
@@ -301,20 +310,29 @@
"create database %s with encoding 'UTF8'" % (self.databaseName)
)
except:
- execSchema = False
+ # database already exists
+ executeSQL = False
else:
- execSchema = True
+ # database does not yet exist; if dump file exists, execute it, otherwise
+ # execute schema
+ executeSQL = True
+ sqlToExecute = self.schema
+ if self.importFileName:
+ importFilePath = CachingFilePath(self.importFileName)
+ if importFilePath.exists():
+ sqlToExecute = importFilePath.getContent()
createDatabaseCursor.close()
createDatabaseConn.close()
- if execSchema:
+ if executeSQL:
connection = self.produceConnection()
cursor = connection.cursor()
- cursor.execute(self.schema)
+ cursor.execute(sqlToExecute)
connection.commit()
connection.close()
+ # TODO: anyone know why these two lines are here?
connection = self.produceConnection()
cursor = connection.cursor()
Added: CalendarServer/trunk/txdav/base/datastore/test/importFile.sql
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/test/importFile.sql (rev 0)
+++ CalendarServer/trunk/txdav/base/datastore/test/importFile.sql 2012-11-06 22:01:57 UTC (rev 10005)
@@ -0,0 +1,2 @@
+CREATE TABLE import_test_table (stub varchar);
+INSERT INTO import_test_table values ('value1');
Modified: CalendarServer/trunk/txdav/base/datastore/test/test_subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/test/test_subpostgres.py 2012-11-05 21:28:10 UTC (rev 10004)
+++ CalendarServer/trunk/txdav/base/datastore/test/test_subpostgres.py 2012-11-06 22:01:57 UTC (rev 10005)
@@ -132,3 +132,56 @@
values = cursor.fetchall()
self.assertEquals(values, [["dummy"]])
+ @inlineCallbacks
+ def test_startService_withDumpFile(self):
+ """
+ Assuming a properly configured environment ($PATH points at an 'initdb'
+ and 'postgres', $PYTHONPATH includes pgdb), starting a
+ L{PostgresService} will start the service passed to it, after importing
+ an existing dump file.
+ """
+
+ test = self
+ class SimpleService1(Service):
+
+ instances = []
+ ready = Deferred()
+
+ def __init__(self, connectionFactory):
+ self.connection = connectionFactory()
+ test.addCleanup(self.connection.close)
+ self.instances.append(self)
+
+
+ def startService(self):
+ cursor = self.connection.cursor()
+ try:
+ cursor.execute(
+ "insert into import_test_table values ('value2')"
+ )
+ except:
+ self.ready.errback()
+ else:
+ self.ready.callback(None)
+ finally:
+ cursor.close()
+
+ # The SQL in importFile.sql will get executed, including the insertion of "value1"
+ importFileName = CachingFilePath(__file__).parent().child("importFile.sql").path
+ svc = PostgresService(
+ CachingFilePath("postgres_3.pgdb"),
+ SimpleService1,
+ "",
+ databaseName="dummy_db",
+ testMode=True,
+ importFileName=importFileName
+ )
+ svc.startService()
+ self.addCleanup(svc.stopService)
+ yield SimpleService1.ready
+ connection = SimpleService1.instances[0].connection
+ cursor = connection.cursor()
+ cursor.execute("select * from import_test_table")
+ values = cursor.fetchall()
+ self.assertEquals(values, [["value1"],["value2"]])
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20121106/fd29c3b7/attachment-0001.html>
More information about the calendarserver-changes
mailing list