[CalendarServer-changes] [11816] CalendarServer/trunk/txdav/base/datastore/subpostgres.py
source_changes at macosforge.org
source_changes at macosforge.org
Tue Oct 15 10:00:58 PDT 2013
Revision: 11816
http://trac.calendarserver.org//changeset/11816
Author: sagen at apple.com
Date: 2013-10-15 10:00:57 -0700 (Tue, 15 Oct 2013)
Log Message:
-----------
First, try to start postgres using pgctl. If that succeeds, we're responsible for stopping it later; if that fails, just try to connect because there is probably already one running. If that succeeds, we're not responsible for stopping postgres; if it fails, give up.
Modified Paths:
--------------
CalendarServer/trunk/txdav/base/datastore/subpostgres.py
Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2013-10-14 21:24:57 UTC (rev 11815)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2013-10-15 17:00:57 UTC (rev 11816)
@@ -454,6 +454,10 @@
self.deactivateDelayedShutdown()
def gotReady(result):
+ """
+ We started postgres; we're responsible for stopping it later.
+ Call pgCtl status to get the pid.
+ """
log.warn("{cmd} exited", cmd=pgCtl)
self.shouldStopDatabase = True
d = Deferred()
@@ -465,13 +469,32 @@
)
return d.addCallback(gotStatus)
- def reportit(f):
- log.failure("starting postgres", f)
+ def couldNotStart(f):
+ """
+ There was an error trying to start postgres. Try to connect
+ because it might already be running. In this case, we won't
+ be the one to stop it.
+ """
+ d = Deferred()
+ statusMonitor = CapturingProcessProtocol(d, None)
+ self.reactor.spawnProcess(
+ statusMonitor, pgCtl, [pgCtl, "status"],
+ env=self.env, path=self.workingDir.path,
+ uid=self.uid, gid=self.gid,
+ )
+ return d.addCallback(gotStatus).addErrback(giveUp)
+
+ def giveUp(f):
+ """
+ We can't start postgres or connect to a running instance. Shut
+ down.
+ """
+ log.failure("Can't start or connect to postgres", f)
self.deactivateDelayedShutdown()
self.reactor.stop()
self.monitor.completionDeferred.addCallback(
- gotReady).addErrback(reportit)
+ gotReady).addErrback(couldNotStart)
shouldStopDatabase = False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20131015/adba836e/attachment.html>
More information about the calendarserver-changes
mailing list