10

drush @mysite cget system.maintenance shows:

message: '@mysite is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en

Drupal 8 uses state values to record transient state, so drush @mysite sget system.maintenance_mode gives me a 1 or a 0.

But, try as I may, I cannot see how to set the boolean. I've tried:

$ drush @mysite sset system.maintenance.mode "TRUE" --format=boolean
$ drush @mysite sget system.maintenance_mode
0
$ drush @mysite sset system.maintenance.mode "TRUE" --format=auto
$ drush @mysite sget system.maintenance_mode
0
$ drush @mysite sset system.maintenance.mode true --format=auto
$ drush @mysite sget system.maintenance_mode
0
$ drush @mysite sset system.maintenance.mode true --format=boolean
$ drush @mysite sget system.maintenance_mode 
0  

What's the secret?

0
24

system.maintenance_mode is not a boolean, it is an integer:

drush ev "var_dump(\Drupal::state()->get('system.maintenance_mode'));"

Result:

int(0)

The answer to the question, how to use drush to put a site in maintenance mode:

drush sset system.maintenance_mode 1
2
  • 2
    It's worth noting here that if the site has never BEEN in maintenance mode before, the system.maintenance_mode variable doesn't exist, and the above drush ev command actually returns bool(false), which is misleading. – Dale Anderson Dec 7 '17 at 18:42
  • @DaleAnderson can you update the answer to be "mo betta"? – Elijah Lynn May 10 '19 at 16:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.