Putting a Drupal site into maintenance mode using Drush 3.0

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
Chris Charlton's picture

I saw someone post to how they run a custom SQL script to put a Drupal site into maintenance mode using Drush's SQL commands, but here's the easier way without any SQL code necessary. Using Drush 3.0 we can turn a site on and off in a split second using the following command:

drush vset site_offline 1

To turn the site back online we run the same command but change the 1 to a 0, like so:

drush vset site_offline 0

*To learn more about the VSET command for Drush just type: drush help vset

Comments

does not work with 7.x

atchijov's picture

It looks like 7.x uses different variable name

maintenance_mode

And, this variable value has to be number ( after vset it is string ).

And, once I patched drush to make it honor variable type (by asking old value and casting new value to the same type as old value), I can put site in "maintenance_mode", but can not get it out of it. It looks like some more magic needed (alternatively it may be D7 bug).

Any comments will be highly appreciated.

Andrei
www.touchnoc.com

Knowledge

kingandy's picture

Drush seems to be aware of the change, and sets the right variable accordingly...

> drush vset site_offline 0
maintenance_mode was set to 0.

Correction

atchijov's picture

Ops... it does work if you accompanies vset with cache-clear (without any patches to drush, sorry).

So to put site offline:

vset --always-set maintenance_mode 1
cache-clear all

to bring it back:

vset --always-set maintenance_mode 0
cache-clear all

Andrei
www.touchnoc.com

Why must we clear the cache there?

Jonathan Peterson's picture

atchijov, do you know why it's necessary to clear the cache after changing the variable setting? I thought that the Drupal boot sequence checked the value of site_online/maintenance_mode before doing anything else, and that it'd note that we were in maintenance mode before bothering to check the cache. Obviously I'm wrong, but ... why?

I ask because I'd like to be able to bring my sites online or offline without invalidating the cache unnecessarily.

There is a variables cache in

moshe weitzman's picture

There is a variables cache in the 'cache' table. You could delete it with DELETE from cache WHERE cid=variables or somesuch.

Thanks, for the comment re

jrsinclair's picture

Thanks, for the comment re Drupal 7. I've been wondering how to do that for ages.

and for the noob

robertwb's picture

For noobs to drush, like I was about 10 minutes ago - you will need to either be in the drupal install root directory that you wish to operate on, or you need to use the drush "--root" switch. So, for my case, I just took a site out of maintenance mode as follows (D7):

drush vset maintenance_mode 0 --root=/var/www/html/u/

Thanks for this little tutorial,
r.b.

thanks.

teekath's picture

thanks. this is helpful.

drush

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: