Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py (11815 => 11816)
--- 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