3

I have a multi-site setup where 3 different sites share the same codebase. All of the modules are in the all/modules folder so they all have the exact same modules. I want to update the modules and core for the codebase with drush but I can't find a way to do it.

There is no settings.php file in sites/default so drush is throwing an error. Do I need to just create a dummy database so drush can connect and update the modules? Obviously I will have to run update.php on the sites after the updates are made.

The databases are separated, they just share modules and core.

7
  • 1
    Try drush @sites <command>, works for me on a couple of multisite installs. I don't have aliases set up for those so I guess sites is a general alias
    – Clive
    Commented Sep 27, 2013 at 15:37
  • Why don't you want to separate the database?
    – AgA
    Commented Sep 27, 2013 at 15:38
  • Each site has a separate DB, they just share modules and core.
    – jsheffers
    Commented Sep 27, 2013 at 15:39
  • @Clive Hmm, that throws an error saying I need a higher bootstrap
    – jsheffers
    Commented Sep 27, 2013 at 15:40
  • Similar to drupal.stackexchange.com/questions/45808/…
    – Steven
    Commented Sep 27, 2013 at 16:02

5 Answers 5

6

Instead of applying the updates to each individual site by using @sites which never worked, I was able to achieve it by running the updates on one specific site. Here is the code that worked for me:

drush -l example.com pm-update

example.com being the name of my symlink. Side note: I did not have to create a drush alias for this to work.

1
  • 1
    This is the correct answer, presuming that you have the same modules enabled in each site. If some of the other sites have additional modules enabled, you might miss those unless you pm-updatecode each site individually. Also, it would be a good idea to copy the sites to dev, run the update there, test (!), then take the production sites offline, copy the code from dev, and run updatedb on all of the prod sites. Sometimes, an innocuous-looking update can take down a site, and there is no "undo" for updatedb! Commented Sep 28, 2013 at 5:01
0

I have a similar set up - multiple sites using the same codebase and different DBs. I use a shell script to run the same drush command through each site. The script is below - it's customised to my server set up. The relevant bits are:

My Drupal root directory is /var/www/drupal7

Each site (in drupal7/sites) contains ".d7." in the name.

The script below (called d7_all_sites) can run 3 drush commands on each of my sites: clear all caches, put sites in/out of maintenance mode, and update the database. The command is given by a parameter. So, when I update modules, I do this ...

$ d7_all_sites mm 1 ## puts all sites into maintenance mode
$ drush up ## updates the modules
$ d7_all_sites updb ## updates each site's DB schema
$ d7_all_sites mm 0 ## takes all sites out of maintenance mode

I'm a scripting novice, so any suggestions to improve the script are very welcome.

#!/bin/bash
# test that at least one parameter if given, else return error message & exit
if [ $# -eq 0 ]
then
echo -e "\n  You must supply a valid parameter ...\n    cc to clear caches.\n    mm [0 or 1] for maintenance mode (0=online, 1=offline).\n    updb to update databases.\n"
exit 2
fi
## clear all caches command
if [ $1 = "cc" ]
then
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Clearing caches on $SITE ...
drush --uri=$SITE --root=/var/www/drupal7 cache-clear all
done
exit 0
fi
## maintenance mode
if [ $1 = "mm" ]
then
if [ $# -ne 2 ]
then
echo -e "\n  You must supply a parameter ...\n    0 for online.\n    1 for offline.\n"
exit 2
else
if [ $2 -eq 0 ]
then
text="online ..."
else
if [ $2 -eq 1 ]
then
text="offline ..."
echo -e "\n  You must supply a parameter ...\n    0 for online.\n    1 for offline.\n"
exit 2
fi
fi
fi
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo 
echo Putting $SITE $text
drush --uri=$SITE --root=/var/www/drupal7 vset --exact --yes maintenance_mode $2
done
exit 0
fi
# update databases
if [ $1 = "updb" ]
then
for SITE in `ls /var/www/drupal7/sites | grep ".d7."`;
do
echo
echo Checking $SITE for database updates ...
drush --uri=$SITE --root=/var/www/drupal7 --yes updatedb
done
exit 0
fi
# if no commands have been run, return an error message
echo -e "\n  You must supply a valid parameter ...\n    cc to clear caches.\n    mm [0 or 1] for maintenance mode (0=online, 1=offline).\n    updb to update databases.\n"
0

Do you have 3 different sites/sitename.com/ directories? If so, you'll want to cd into each of them one at a time and run drush up in each.

The first time you run it it will download the new modules and run the update hooks on that site's DB and the next two times it will see that they're already downloaded so it will just run the update hooks on the other two sites' DB's.

0

Here's what I do to update a multi-site setup:

for d in sites/*; do pushd $d; drush up -y; popd; done
0

It's in PHP, but this is what I use from inside my sites folder.

Example usage from the command line:

cd /path/to/drupal/sites
php drush_updates.php

The file:

<?php    
/**
 * Run db updates on all of the sites in the multisite, using Drush
 */    
print "\n\n***************************************************\n";
print "This script will find all of the site dirs and run drush updb -y on them.\n\n";

$start_dir = ".";
$files = scandir($start_dir);

foreach ($files as $file) {

  if (is_dir($file) && $file != "." && $file != ".." && $file != "all") {
    print "drush updb -y on $file...\n";      
    chdir($file);        
    system("drush updb -y");
    chdir("..");
  }
}

print "\n\n*******************************************\n";
print "Finished!\n\n";    
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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