Question

I have created a custom module with a .install file, which includes some hook_update_N() hooks, used to update existing nodes.

Whenever I run drush updb, the site automatically enters maintenance mode (anonymous requests get a 503), and if the update is successful, the site goes back online, all by itself.

I couldn't find any resource on the web about this situation.

Is it normal? Is there a way to disable this behavior?

Was it helpful?

Solution

It does look to be normal, yes. Drush's UpdateDBCommands::updateBatch, which is responsible for processing the updates, contains this:

batch_set($batch);

// See updateFinished() for the restore of maint mode.
$this->maintenanceModeOriginalState = \Drupal::service('state')->get('system.maintenance_mode');
\Drupal::service('state')->set('system.maintenance_mode', true);
drush_backend_batch_process();

The code deliberately sets maintenance mode to true before processing the batch, and then restores the original state when it's done.

Running drush help updb lists the following options:

  • --cache-clear[=CACHE-CLEAR] Clear caches upon completion. [default: "true"]
  • --entity-updates Run automatic entity schema updates at the end of any update hooks.
  • --post-updates[=POST-UPDATES] Run post updates after hook_update_n and entity updates. [default: "true"]
  • --no-cache-clear Negate --cache-clear option.
  • --no-post-updates Negate --post-updates option.

So there doesn't seem to be an obvious way to disable the behaviour. But if you're updating the database you probably don't want people to be able to access the site at the same time. There's a good explanation for that here.

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top