How can I take a site offline using Drush?
Drupal 8: drush sset system.maintenance_mode TRUE
Drupal 7: drush vset maintenance_mode 1
Drupal 6: drush vset site_offline 1
-
7If you are using drush-5.x, you may now simply use "drush vset maintenance_mode 1". Drush will rewrite maintenance_mode to site_offline for Drupal 6. (This feature is newer than the above answer.) – greg_1_anderson Dec 7 '11 at 18:28
-
6
-
1Drupal 8:
drush state-set system.maintenance_mode 1
(I don't like drush's aliases) – Andrea Apr 29 '16 at 14:23
First you should cd into the correct directory so that you are within the Drupal directory. If you are using a multi site installation cd into the correct sites/sitename directory or specify the correct -l setting
In Drupal 6 only this command is actually required:
$ drush vset --yes site_offline 1;
Also in Drupal 6 you can use the following commands if you wish to specify a message to show to the users of the site whilst it is down.
$ drush vset --yes site_offline_message "This site is being maintained";
$ drush vset --yes site_offline 1;
In Drupal 7 use following command to put the site into maintenance mode:
$ drush vset --yes maintenance_mode 1;
To set an a specific message use:
$ drush variable-set --yes maintenance_mode_message "This site is being maintained"
It could be necessary to clear caches that the changes of these variables take effect:
$ drush cc all
-
1This does not work if the variable does not already exist. You're missing the --always-set parameter. – Tobias Sjösten Mar 2 '11 at 21:10
-
1The variable gets created by the installer though. Go install a fresh drupal and look in the variable table. – Stewart Robinson Mar 2 '11 at 21:23
-
1Upvoted due to including the site_offline_message part. I believe the Drupal 7 equivalent of site_offline_message is maintenance_mode_message? – lolcode Mar 27 '13 at 13:32
-
You don't need to clear the cache, variable_set() does that for you: api.drupal.org/api/drupal/includes%21bootstrap.inc/function/… – mvc Jun 1 '16 at 12:30
-
1variable_set only clears two caches. cache_clear_all('variables', 'cache_bootstrap'); – Stewart Robinson Jul 12 '16 at 13:15
To do this with Drupal 8 and Drush 8.x use the state-set
command:
drush sset system.maintenance_mode 1
At first, I assumed this would be something I would set with drush config-set system.maintenance
, however the only keys in that configuration are message
(the message displayed when maintenance mode is enabled) and langcode
(the language code for said message).
This is controlled by a variable, site_offline.
$ drush vset --always-set site_offline 1
You could also set the offline message this way.
$ drush vset --always-set site_offline_message 'Please try again later!'
-
This would bring the site back up if it is down for maintenance. – Stewart Robinson Mar 2 '11 at 21:05
-
Thanks for pointing that out. Of course it should be set to 1, nothing else. – Tobias Sjösten Mar 2 '11 at 21:08
From Drupal 6 use:
drush vset site_offline 1
To take it out of maintenance:
drush vset site_offline 0
drush cc all