Posted by Chris Charlton on June 23, 2010 at 10:21pm
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
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
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
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?
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
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
Thanks, for the comment re Drupal 7. I've been wondering how to do that for ages.
and for the noob
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.
thanks. this is helpful.