Problem/Motivation
We use Drupal's multi-site functionality to version control different server environments settings and drush runtime configurations separately.
sites/example.com/settings.php
sites/example.com/drushrc.php
sites/dev.example.com/settings.php
sites/dev.example.com/drushrc.php
sites/example.local/settings.php
sites/example.local/drushrc.php
We have been using drushrc.php in the Drupal root, to specify which environment to load via the $options['uri'] = "http://example.local';. This would allow us to execute typical drush commands inside our multi-site (server environment) configuration, without having to specify a default --uri option with every command.
This is no longer possible with Drush 5, because it only loads the drushrc.php file in the Drupal root once Drupal/Drush has been bootstrapped with an appropriate --uri option.
Proposed resolution
Move the drushrc.php out of the Drupal root folder, to sites/all/drush/drushrc.php, where the $options['uri'] is loaded appropriately. This file may then be symbolically linked from one of the multi-site's drushrc.php files, to load the appropriate uri, depending on the server environment.
Original report by jwilson3
I just updated drush from a git pull on the master branch... and to my dismay the css-js (which was awesomely recently renamed from css+js ;-) simply does not work any more.
Executing drush cache-clear from any location inside a drupal_root folder, results in the following options:
~user@web:~/drupal_root $ drush cache-clear
Enter a number to choose which cache to clear.
[0] : Cancel
[1] : all
[2] : drush
[3] : registry
However, if I specify the --uri option, it offers a plethora more options:
~user@web:~/drupal_root $ drush cache-clear --uri=example.com
Enter a number to choose which cache to clear.
[0] : Cancel
[1] : all
[2] : drush
[3] : theme-registry
[4] : menu
[5] : css-js
[6] : block
[7] : module-list
[8] : theme-list
[9] : registry
[10] : views
My Drupal / Drush configuration runs off a symbolic link to a specific site folder, based on the server environment I'm currently on (this has worked fine in the past, but i dont know if this is the cause for not finding the drushrc.php in the drupal root or what):
~/drupal_root/drushrc.php --> symbolic link to ~/drupal_root/sites/example.com/drushrc.php
Other core drush commands work flawlessly, and don't seem to show any symptoms of the missing --uri option.
Comments
Comment #1
jwilson3Note,
drush cache-clear drushhas no effect on this issue, the extra options are still missing.Comment #2
jwilson3More debugging:
If I replace the default sites/default folder provided by Drupal with a symbolic link to my site folder, the cache-clear options are found.
ie, this works:
Comment #3
jwilson3The real issue here is that
drushrc.phpis apparently no longer being sourced from the Drupal root folder, as it was in drush 4.xthis excerpt from
examples/example.drushrc.phpexplains the issue...We have been using
drushrc.phpin the drupal root, to *specify* which environment to load via the$options['uri'] = "http://example.local';.We're looking into another way to solve this, but any suggestions are recommended. Thanks.
Comment #3.0
jwilson3Fixed the long form --uri (was inadvertently specified as --url) I usually use the shorthand version.... -l (dash L).
Comment #4
jwilson3For the moment, the only solution is to symlink sites/default/settings.php to the proper settings file in the multi-site folder.
eg
sites/default/settings.php --> symlink to: sites/example.local/settings.php (on local environment)
sites/default/settings.php --> symlink to: sites/stage.example.com/settings.php (on staging environment)
sites/default/settings.php --> symlink to: sites/example.com/settings.php (on production environment)
Anyone know of another way to do this?
Comment #5
moshe weitzman commentedsites/all/drush replaced drupal root as location for config/alias/command files
Comment #6
greg.1.anderson commentedDo you think we should help folks out by printing a warning if we find a drushrc.php file at the Drupal root? A lot of people upgrading from Drush 4 will probably encounter this.
Comment #6.0
greg.1.anderson commentedCreate summary from comment #3 excerpt, to better explain the real issue.
Comment #6.1
jwilson3Added Proposed Solution, and elaborated on Problem/Motivation.
Comment #7
jwilson3Greg,
I've moved my symbolically linked drushrc.php out of drupal root into sites/all/drush and this worked perfectly. I've added this to the Proposed Solution above.
However, in my testing I wasn't actually ever able to get a drushrc.php to even *load* from the Drupal root with drush 5, even after putting the proper uri in sites/all/drush/drushrc.php
Comment #8
moshe weitzman commented@Greg - I think the existing Change Notice is sufficient. I'd not take the file_exists() hit on every request.
Comment #9
greg.1.anderson commented@jwilson3: you should be able to re-enable the Drupal root as an install location for drushrc.php by setting
$options['config'] = 'path';in a drushrc.php file that is being loaded. If you use the one in sites/all/drush/drushrc.php, setting a path relative to __FILE__ should work. Seems easier to just move the file to the new location, though.Comment #10
jwilson3Right, ok... except example.drushrc.php claims that drushrc.php would be loaded in the drupal root, if --root or --uri would be specified:
but this is clearly not the case.
So, ideally, there needs to be two changes:
- have Drush 5 check for drushrc.php in a Drupal root, even though it doesnt source the file, and provide a deprecated warning.
- update example.drushrc.php to explain properly how to get drushrc.php to be sourced from a Drupal root.
thoughts?
Comment #11
greg.1.anderson commentedYes, we need to update the documentation here; however, per #8, we are not going to provide a warning if a config file is found in the old location.
Comment #12
jwilson3Ah, my bad. I missed comment #8.
Comment #13
jwilson3Here's a patch for documentation examples/example.drushrc.php.
Also, I noticed that the column wrap in that file is not anywhere close to 80 columns, and sometimes varies widely. I wouldn't mind adjusting that and providing a patch, as long as it could get applied reasonably quickly, so as not to have to continuously re-roll.
UPDATE: There were two whitespace cleanups that snuck into the patch, because my editor is set to remove them by default. I can remove if needed.
Comment #14
greg.1.anderson commentedFixing whitespace is a good feature. Docs update looks good; thanks.
I'll probably have time to commit this patch, and any provided rewrapping patch, later this afternoon.
Comment #15
jwilson3Here's a general doc cleanup of the example.drushrc.php
I stumbled across one thing... there is an example for options to `drush core-cli`, but that command appears to have been removed from Drush 5 (is that correct?).
After this patch is applied I'd also like to reorganize a few of the entries and group them together more logically, for example, by putting the general Drush global options at the top, and then more specific but shared common commands' options below....
UPDATE:
e.g.--package-handlerseems out of place between the--default-majorand the--includeoptions, which both apply to Drush's bootstrap itself.^ that was a poor example.. heres a better one:
--self-update, --default-major, --package-handlerwhich apply to download and update commands, seem out of place between the--configand the--includeoptions, which apply to Drush's bootstrap itself. Also, the-voption could be moved up to the top along side-land-r.Comment #16
jwilson3Fixed two more tiny mistakes in the first couple sentences.
Comment #17
greg.1.anderson commentedLooks much better; thanks.
Comment #18.0
(not verified) commentedSyntax error