Exit maintenance script with non-zero status if execute() returns false
authorTim Starling <tstarling@wikimedia.org>
Sun, 20 May 2018 14:26:46 +0000 (16:26 +0200)
committerTim Starling <tstarling@wikimedia.org>
Thu, 31 May 2018 06:46:14 +0000 (16:46 +1000)
There's a whole lot of shutdown code in doMaintenance.php that is
skipped when you use exit() directly. In HHVM by default, destructors
are not even called.

There are a few cases where maintenance scripts want to do something after
doMaintenance.php returns, so returning null should continue to mean no exit.

Change-Id: I0891e2ee3af7ef2c64c03b70edcf9e281ce1e7ba

maintenance/Maintenance.php
maintenance/doMaintenance.php

index 13fee9c..80fd7b9 100644 (file)
@@ -202,6 +202,11 @@ abstract class Maintenance {
 
        /**
         * Do the actual work. All child classes will need to implement this
+        *
+        * @return bool|null True for success, false for failure. Not returning
+        *   a value, or returning null, is also interpreted as success. Returning
+        *   false for failure will cause doMaintenance.php to exit the process
+        *   with a non-zero exit status.
         */
        abstract public function execute();
 
index f3fb32c..1f1a4c7 100644 (file)
@@ -91,7 +91,7 @@ $maintenance->checkRequiredExtensions();
 $maintenance->setAgentAndTriggers();
 
 // Do the work
-$maintenance->execute();
+$success = $maintenance->execute();
 
 // Potentially debug globals
 $maintenance->globals();
@@ -111,3 +111,8 @@ if ( isset( $lbFactory ) ) {
        $lbFactory->commitMasterChanges( 'doMaintenance' );
        $lbFactory->shutdown( $lbFactory::SHUTDOWN_NO_CHRONPROT );
 }
+
+// Exit with an error status if execute() returned false
+if ( $success === false ) {
+       exit( 1 );
+}