4

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?

1 Answer 1

5

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.

2
  • Thank you. So I suppose if I use update.php instead of drush, I can avoid having the site enter maintenance mode, as it provides you an option there.
    – atwixtor
    Oct 11, 2018 at 19:22
  • 2
    Yes that's the way to get around it, but be sure to read my last edit and Greg's explanation in the linked post as to why that might not be the best idea
    – Clive
    Oct 11, 2018 at 19:23

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .