Drupal 10, the latest version of the open-source digital experience platform with even more features, is here.Drupal upgrade instructions always say to disable all non-core modules before the upgrade and then to enable them again afterwards. If you have a lot of modules this is a real pain, especially because of dependencies many can't be enabled or disabled until others are first enabled or disabled. Not to mention the chances to make a mistake!
I'm unskilled at Drupal, at Drush, and at shell scripting, but nontheless I made a couple shell scripts that use Drush to disable or re-enable all my non-core modules. These scripts are guaranteed to be buggy and slipshod, so before you play with them back everything up and check that your life-insurance policy is up to date. Seriously, I'd love to get feedback about how to make these better, but they seem to work for me with my Drupal 6.13 system running on Ubuntu 8.10 (Ibex).
These scripts assume that Drush 2.0 is installed and running and that your Drupal root is at /var/www and that you are working with Drupal 6. Actually, the scripts probably assume a lot of other stuff too, but I'm too dumb to even know what.
Disable Script
The first script disables all the non-core modules. It uses the Drush "statusmodules" command which returns ALL modules, including the core ones - and woe be to you if you disable the core modules. So the script gets the list of all modules, then removes the 5 core modules (Block, Filter, Node, System, and User) from the list. Then it prepends the "drush disable" command to the front of the list, and saves that whole thing as a new shell script, makes the script executable, and then executes it.
cd /var/www
drush statusmodules --pipe >originalmodulelist.txt
sed -e 's/ block / /g' -e 's/ filter / /g' -e 's/ node / /g' -e 's/ system / /g' -e 's/ user / /g' originalmodulelist.txt >trimmedmodulelist.txt
sed 's/^/drush disable /' trimmedmodulelist.txt >disablemodules
sudo chmod 777 disablemodules
sudo ./disablemodules
Re-Enable Script
The second script is even simpler. It makes a copy of the shell script created by the Disable Script, changes the "drush disable" command to be "drush enable" and then pulls the same dopey trick of creating a new shell script and executing it. If for some reason you have lost or moved the earlier script you will be out of luck.
cd /var/www
sed 's/disable/enable/' disablemodules >reenablemodules
sudo chmod 777 reenablemodules
sudo ./reenablemodules
My wish is that someone who knows what they are doing would help me to improve these scripts (and the instructions) to the point where they could be placed in the Documentation part of drupal.org.










Comments
Comment #1
xlyz CreditAttribution: xlyz commentedgenerate list
disable
enable
enjoy
Comment #2
steve02476 CreditAttribution: steve02476 commentedThat looks great, thanks, I'll try it out. -Steve
Comment #3
xlyz CreditAttribution: xlyz commentedbtw, to put your site in maintenance mode:
and to put it back on line
Comment #4
moshe weitzman CreditAttribution: moshe weitzman commentednot sure what needs doing here.
Comment #5
xlyz CreditAttribution: xlyz commentedmaybe put a note in the docs?
Comment #6
ChrisRut CreditAttribution: ChrisRut commented:subscribe:
Comment #7
steve02476 CreditAttribution: steve02476 commentedSince I posted this, should I do something to "close" it? I don't know what's expected.
Comment #8
moshe weitzman CreditAttribution: moshe weitzman commentedSuch a rare event. Please add drush integration to the module that does this (I forget the name).
Comment #9
nedjoSee http://drupal.org/project/contrib_toggle (which looks to be discontinued for reasons noted on the module's page).
Comment #10
protoplasm CreditAttribution: protoplasm commentedI couldn't get the methods in #1 to work. I believe it may because drush itself has changed.
You can
drush pm-enablea list of modules separated by spaces, but with about 290 non-core modules this is more difficult than just checking things off. It would be nice if there was a method to extract the code names for the enabled non-core modules on the current site (maybe I missed something?). Not seeing a command to do that, I went to the update.php page, selected & copied my listing, removed the ' module:' with a replace command in a word processor and then replaced paragraph formatting with a space and that gave me a space separated list of most of my modules I wanted to enable. It worked for most. I got a couple of errors where it didn't work, but it did save me lots of time and enabled most of the files for me.After almost 4 years, I decided yesterday to learn drush and boy-oh-boy it is a time saver for updating modules. Again, the only problem is finding the code names for the modules. Since I work off the update status page to upgrade my module versions, I kind of wish that 'they' would print out the code names for the file directly on that page.
Anyways, hats off to the developer(s) of drush. What an amazing tool!
Comment #11
moshe weitzman CreditAttribution: moshe weitzman commentedhttp://2bits.com/articles/server-indigestion-the-drupal-contributed-modu...
Comment #12
protoplasm CreditAttribution: protoplasm commentedThanks for your reply. "mysql> select name from system where type = 'module' and status = 1 order by name"... Fantastic.
(The article is also on server bloat. It's a tribute to drupal that even with all the modules (I'm including the modules within modules in my count) and thousands of pages, pictures, and users--the site is reasonably responsive. The bloat does need to go).
Thanks again!
Comment #13
xjmSee:
#440962: a way to list enabled modules so that this output can be fed to a disable command - like in drush_mm module
#888480: drush pm-list: way to exclude rather than include a package
Comment #14
ben4asterisk CreditAttribution: ben4asterisk commentedLinks at post 13 by xjm explain getting a list of all the enabled modules.
drush pm-list --pipe --type=module --status=enabled
Again this works fine for getting all enabled modules including Core-required modules. Going by the recommended way of upgrading, it would be good to disable all non-Core-required modules.
drush pm-list --type=module --package="Other"
can be used to get a list of all package types. But this is painful to list different types.
It would be good if drush has a feature to not include certain packages. I am not sure if such a thing already exists.
So as of now, am using this script to disable all non-Core-required modules (slight change in the scripts above).
#] drush pm-list --type=module --status=enabled | awk '/\(/ && /\)/ && ! /[Cc]ore.*-.*[Rr]equired/' | sed 's/.*(\(.*\)).*/\1/' > ModulesWoutCore
#] drush pm-disable `cat ModulesWoutCore`
Enable back when rest of upgrade is complete.
#] drush pm-enable `cat ModulesWoutCore`
HIH for ppl who are looking for this.
Comment #15
xjmRe: #14, I proposed an option for this (without all the awk craziness) in #888480: drush pm-list: way to exclude rather than include a package (patch available there), but it was marked "won't fix." If you'd like a simpler way of excluding packages, I'd say follow up on that issue.
Comment #16
a8w4Here is my version without awk (also i really don't like backticks...) and it generates a sorted list, which is nicer for checking the list before firing the disable part:
Comment #17
drupalpeter CreditAttribution: drupalpeter commentedGreat! Thanks - this will probably save me a lot of headaches.
Comment #18
pumpkinkid CreditAttribution: pumpkinkid commentedMight be good to note that this also disables the Core Optional modules...
This would only disable everything not included in core (which is what is needed for Drupal Upgrades).
Note that you will get a notice that says some modules are "a required module and can't be disabled." This should be fine.
Comment #19
13rac1 CreditAttribution: 13rac1 commentedDisable non-core in one line with:
Comment #20
BassPlaya CreditAttribution: BassPlaya commentedI've tried #16 and #18 on a Drupal 6 install with drush_version=4.5 and those worked for me!
Thanx!
Comment #21
aiphes#19 works like a charm
Comment #22
rurri CreditAttribution: rurri commented#19 worked great although I would definitely send the module list to a file first.
Comment #23
Screenack CreditAttribution: Screenack commentedMac Lion's xargs (as does BSD's) lacks the --arg-file (-a) parameter. This worked for me on Mac:
(first command as is)
cat modules.txt | xargs drush -y dis #since you can batch uninstall no problems
cat modules.txt | xargs -L 1 drush -y en #may choke without the "one line at a time" command
If you run the drush disable command one at a time, (-L 1) you could prevent dependent modules, later in the list, from uninstalling. It seems passing module list as a batch is both quicker and more effective.
Comment #24
Anonymous (not verified) CreditAttribution: Anonymous commentedThere may be some modules which don't properly get enabled (or disabled). If you use `xargs`, it will die before properly enabling/disabling all of these modules.
Instead, you could use a for loop, though this will take longer:
Why enable all modules, you ask? One of our CI boxes needed to enable all modules so that we could run the update module against all our modules we provide so that we can easily determine if we need to take any module updates. I would NEVER recommend or condone the enabling of all modules on a production system.