[CalendarServer-changes] [7478] CalendarServer/branches/users/glyph/new-export/txdav/base/datastore/ subpostgres.py

source_changes at macosforge.org source_changes at macosforge.org
Mon May 16 07:47:01 PDT 2011


Revision: 7478
          http://trac.macosforge.org/projects/calendarserver/changeset/7478
Author:   glyph at apple.com
Date:     2011-05-16 07:47:01 -0700 (Mon, 16 May 2011)
Log Message:
-----------
remember whether starting the database succeeded, and only stop it if so.

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/new-export/txdav/base/datastore/subpostgres.py

Modified: CalendarServer/branches/users/glyph/new-export/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/branches/users/glyph/new-export/txdav/base/datastore/subpostgres.py	2011-05-16 14:46:38 UTC (rev 7477)
+++ CalendarServer/branches/users/glyph/new-export/txdav/base/datastore/subpostgres.py	2011-05-16 14:47:01 UTC (rev 7478)
@@ -87,8 +87,9 @@
 
     def processEnded(self, reason):
         log.msg("postgres process ended %r" % (reason,))
+        result = (reason.value.status == 0)
         self.lineReceiver.connectionLost(reason)
-        self.completionDeferred.callback(None)
+        self.completionDeferred.callback(result)
 
 
 
@@ -362,6 +363,7 @@
         )
         self.monitor = monitor
         def gotReady(result):
+            self.shouldStopDatabase = result
             self.ready()
             self.deactivateDelayedShutdown()
         def reportit(f):
@@ -370,6 +372,7 @@
         self.monitor.completionDeferred.addCallback(
             gotReady).addErrback(reportit)
 
+    shouldStopDatabase = False
 
     def startService(self):
         MultiService.startService(self)
@@ -423,14 +426,17 @@
             d = MultiService.stopService(self)
 
         def superStopped(result):
-            monitor = _PostgresMonitor()
-            pg_ctl = which("pg_ctl")[0]
-            reactor.spawnProcess(monitor, pg_ctl,
-                [pg_ctl, '-l', 'logfile', 'stop'],
-                self.env,
-                uid=self.uid, gid=self.gid,
-            )
-            return monitor.completionDeferred
+            # If pg_ctl's startup wasn't successful, don't bother to stop the
+            # database.  (This also happens in command-line tools.)
+            if self.shouldStopDatabase:
+                monitor = _PostgresMonitor()
+                pg_ctl = which("pg_ctl")[0]
+                reactor.spawnProcess(monitor, pg_ctl,
+                    [pg_ctl, '-l', 'logfile', 'stop'],
+                    self.env,
+                    uid=self.uid, gid=self.gid,
+                )
+                return monitor.completionDeferred
         return d.addCallback(superStopped)
 
 #        def maybeStopSubprocess(result):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110516/80017298/attachment.html>


More information about the calendarserver-changes mailing list