Open crittermike opened 8 years ago
I can't reproduce this.
The line you highlighted is chdir($c). $c is not the Drush in your vendor dir, it is the original cwd. See where it is defined above.
Slightly off topic, but you can carefully control how Drush gets called in your project. See instructions at top of https://github.com/drush-ops/drush/blob/master/examples/drush.wrapper. For a more real world use case, see https://github.com/drupal-composer/drupal-project/pull/98.
$c is not the Drush in your vendor dir, it is the original cwd
I think that's the problem. If the cwd changes, then it loses the fact that you were originally in /build/html (i.e., the Drupal docroot), and it can't find the docroot anymore. No?
I don't see how the value of $c can ever change.
woops, i see it now. will try to reproduce it. I am using a setup like yours but without a build dir. just html under project root. maybe thats why i dont see it yet,
Can you share a composer.json which installs drupal into build/html, depends on drush, etc?
Yeah, that may be it, because one of the paths it looks for is ../vendor/bin
(see https://github.com/drush-ops/drush/blob/master/includes/startup.inc#L80) which it sounds like in your case it would find Drush in without having to go up a directory, since your docroot is only 1 level deep as opposed to my 2 levels. In my case it has to go up a directory to be able to find it. At least I'm guessing that could be the difference.
As for a composer.json, I'm using https://github.com/phase2/grunt-drupal-tasks/ (setup instructions here: https://github.com/phase2/grunt-drupal-tasks/blob/master/CONFIG.md#set-up-your-drupal-project) - does that help?
Basically just:
npm install generator-gadget
yo gadget
grunt
...is my setup. Let me know if you want me to give you a zip of what it produces.
I ran those commands and the Drupal root is recognized fine. You can see below that I am invoking a non-local Drush and at the top of the logs in the next section, you see that it handed off control to the local Drush (tmp/grunt-drupal-tasks/vendor/drush/drush/drush.launcher).
~/tmp/grunt-drupal-tasks/build/html $ which drush
/Users/moshe.weitzman/c/h/drush/drush
~/tmp/grunt-drupal-tasks/build/html $ drush st -d
Using the Drush script found at /Users/moshe.weitzman/tmp/grunt-drupal-tasks/vendor/drush/drush/drush.launcher using pcntl_exec
Loading drushrc "/Users/moshe.weitzman/.drush/drushrc.php" into "home.drush" scope. [0.01 sec, 2.54 MB] [bootstrap]
Cache HIT cid: 9.0-dev-commandfiles-0-94bb1c8e0b79fae97cfea1e74d21f0de [0.03 sec, 2.6 MB] [debug]
Bootstrap to phase 0. [0.41 sec, 6.19 MB] [bootstrap]
Trying to bootstrap as far as we can. [0.41 sec, 6.2 MB] [debug]
Drush bootstrap phase : bootstrap_drupal_root() [0.43 sec, 6.57 MB] [bootstrap]
Initialized Drupal 8.1.0-beta1 root directory at /Users/moshe.weitzman/tmp/grunt-drupal-tasks/build/html [0.44 sec, 6.57 MB] [bootstrap]
Find command files for phase 1 (max=7) [0.44 sec, 5.12 MB] [debug]
Cache HIT cid: 9.0-dev-commandfiles-1-700f2a1133a2610d72b7158b6488b3d3 [0.44 sec, 5.13 MB] [debug]
Bootstrap phase bootstrap_drupal_site() failed to validate; continuing at bootstrap_drupal_root(). [0.58 sec, 5.82 MB] [debug]
Found command: core-status (commandfile=core) [0.59 sec, 5.82 MB] [bootstrap]
Loading outputformat engine. [0.9 sec, 7.37 MB] [notice]
Calling hook drush_core_status [0.91 sec, 7.41 MB] [debug]
Returned from hook drush_core_status [0.94 sec, 7.43 MB] [debug]
Drupal version : 8.1.0-beta1
PHP executable : /Applications/Dev Desktop/php5_6/bin/php
PHP configuration : "/Applications/Dev Desktop/php5_6/bin/php.ini"
PHP OS : Darwin
Drush script : /Users/moshe.weitzman/tmp/grunt-drupal-tasks/vendor/drush/drush/drush.php
Drush version : 9.0-dev
Drush temp directory : /tmp
Drush configuration : /Users/moshe.weitzman/.drush/drushrc.php
Drush alias files : /Users/moshe.weitzman/.drush/acquiacom.aliases.drushrc.php "
There are 29 more alias files. Run with --full to see the full list."
Drupal root : /Users/moshe.weitzman/tmp/grunt-drupal-tasks/build/html
Drupal Settings File : MISSING
What command are you running? Maybe it does not bootstrap at all? Please post a log with -d
Dang. I wonder what could be different about my setup then.
Here's a log:
vagrant ➜ testproject/build/html » drush -vd status
Drush preflight prepare loaded autoloader at [preflight]
/var/www/testproject/vendor/autoload.php [0.02 sec, 3.29 MB]
Starting Drush preflight. [0.02 sec, 3.29 MB] [preflight]
Loading drushrc "/home/vagrant/.drush/drushrc.php" into "home.drush" scope. [0.03 sec, 3.3 MB] [bootstrap]
Cache HIT cid: 8.1-dev-commandfiles-0-1277e01df128b7d46897961f16551bb6 [0.05 sec, 3.36 MB] [debug]
Scanning into /etc/drush for /.*aliases\.drush(8|)rc\.php$/ [0.13 sec, 7.26 MB] [debug]
Scanning into /etc/drush for /self\.alias\.drush(8|)rc\.php$/ [0.13 sec, 7.26 MB] [debug]
Scanning into /var/www/testproject/vendor/drush/drush/includes/.. for /.*aliases\.drush(8|)rc\.php$/ [0.13 sec, 7.26 MB] [debug]
Scanning into /var/www/testproject/vendor/drush/drush/includes/.. for /self\.alias\.drush(8|)rc\.php$/ [0.15 sec, 7.26 MB] [debug]
Scanning into /home/vagrant/.drush for /.*aliases\.drush(8|)rc\.php$/ [0.19 sec, 7.27 MB] [debug]
Scanning into /home/vagrant/.drush for /self\.alias\.drush(8|)rc\.php$/ [0.23 sec, 7.27 MB] [debug]
Bootstrap to phase 0. [1.69 sec, 9.92 MB] [bootstrap]
Trying to bootstrap as far as we can. [1.72 sec, 9.93 MB] [debug]
Found command: core-status (commandfile=core) [1.75 sec, 9.93 MB] [bootstrap]
Loading outputformat engine. [1.77 sec, 9.93 MB] [notice]
Calling hook drush_core_status [1.8 sec, 10.03 MB] [debug]
Scanning into /etc/drush for /.*aliases\.drush(8|)rc\.php$/ [1.8 sec, 10.04 MB] [debug]
Scanning into /etc/drush for /.*\.alias\.drush(8|)rc\.php$/ [1.81 sec, 10.04 MB] [debug]
Scanning into /var/www/testproject/vendor/drush/drush/includes/.. for /.*aliases\.drush(8|)rc\.php$/ [1.82 sec, 10.04 MB] [debug]
Scanning into /var/www/testproject/vendor/drush/drush/includes/.. for /.*\.alias\.drush(8|)rc\.php$/ [1.84 sec, 10.05 MB] [debug]
Scanning into /home/vagrant/.drush for /.*aliases\.drush(8|)rc\.php$/ [1.88 sec, 10.05 MB] [debug]
Scanning into /home/vagrant/.drush for /.*\.alias\.drush(8|)rc\.php$/ [1.92 sec, 10.05 MB] [debug]
Returned from hook drush_core_status [1.96 sec, 10.05 MB] [debug]
PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini
PHP OS : Linux
Drush script : /var/www/testproject/vendor/drush/drush/drush.php
Drush version : 8.1-dev
Drush temp directory : /tmp
Drush configuration : /home/vagrant/.drush/drushrc.php
Drush alias files : /home/vagrant/.drush/nexderm-microsite.aliases.drushrc.php /home/vagrant/.drush/rnib.aliases.drushrc.php /home/vagrant/.drush/nexderm.aliases.drushrc.php
/home/vagrant/.drush/nexderm-micro-1.aliases.drushrc.php /home/vagrant/.drush/voyce.aliases.drushrc.php
Command dispatch complete [2.05 sec, 10.21 MB]
Here's a log of sql-connect
as well.
vagrant ➜ testproject/build/html » drush -vd sql-connect
Drush preflight prepare loaded autoloader at [preflight]
/var/www/testproject/vendor/autoload.php [0.02 sec, 3.29 MB]
Starting Drush preflight. [0.02 sec, 3.29 MB] [preflight]
Loading drushrc "/home/vagrant/.drush/drushrc.php" into "home.drush" scope. [0.03 sec, 3.3 MB] [bootstrap]
Cache HIT cid: 8.1-dev-commandfiles-0-1277e01df128b7d46897961f16551bb6 [0.04 sec, 3.36 MB] [debug]
Scanning into /etc/drush for /.*aliases\.drush(8|)rc\.php$/ [0.12 sec, 7.26 MB] [debug]
Scanning into /etc/drush for /self\.alias\.drush(8|)rc\.php$/ [0.12 sec, 7.26 MB] [debug]
Scanning into /var/www/testproject/vendor/drush/drush/includes/.. for /.*aliases\.drush(8|)rc\.php$/ [0.13 sec, 7.26 MB] [debug]
Scanning into /var/www/testproject/vendor/drush/drush/includes/.. for /self\.alias\.drush(8|)rc\.php$/ [0.15 sec, 7.26 MB] [debug]
Scanning into /home/vagrant/.drush for /.*aliases\.drush(8|)rc\.php$/ [0.18 sec, 7.27 MB] [debug]
Scanning into /home/vagrant/.drush for /self\.alias\.drush(8|)rc\.php$/ [0.21 sec, 7.27 MB] [debug]
Bootstrap to phase 0. [1.49 sec, 9.92 MB] [bootstrap]
Bootstrap to phase -1. [1.52 sec, 9.93 MB] [bootstrap]
Found command: sql-connect (commandfile=sql) [1.53 sec, 9.93 MB] [bootstrap]
Calling hook drush_sql_connect [1.56 sec, 10.01 MB] [debug]
5 Unable to load class Drush\Sql\Sql [1.59 sec, 10.02 MB] [error]
6 exception 'Drush\Sql\SqlException' with message 'Unable to find a matching SQL Class. Drush cannot find your database connection details.' in [error]
/var/www/testproject/vendor/drush/drush/commands/sql/sql.drush.inc:597
Stack trace:
#0 /var/www/testproject/vendor/drush/drush/commands/sql/sql.drush.inc(234): drush_sql_get_class()
#1 [internal function]: drush_sql_connect()
#2 /var/www/testproject/vendor/drush/drush/includes/command.inc(366): call_user_func_array('drush_sql_conne...', Array)
#3 /var/www/testproject/vendor/drush/drush/includes/command.inc(217): _drush_invoke_hooks(Array, Array)
#4 [internal function]: drush_command()
#5 /var/www/testproject/vendor/drush/drush/includes/command.inc(185): call_user_func_array('drush_command', Array)
#6 /var/www/testproject/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#7 /var/www/testproject/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#8 /var/www/testproject/vendor/drush/drush/drush.php(12): drush_main()
#9 {main} [1.6 sec, 10.04 MB]
Command dispatch complete [1.6 sec, 9.99 MB] [notice]
Not sure why Drush can't tell it is in a Drupal root. What version of Drupal is installed in build/html? If you add -r, does everything work fine? Post the output of drush --local -d -r /var/www/nba/built/html status
. I think the --local there will cut down on the 'scanning' messages and not affect the analysis. It also eliminates home/vagrant/.drush/drushrc.php as a source of problems.
With the -r
param:
vagrant ➜ testproject/build/html » drush --local -d -r /var/www/testproject/build/html status
Using the Drush script found at /var/www/testproject/vendor/drush/drush/drush.launcher using pcntl_exec
Cache HIT cid: 8.1-dev-commandfiles-0-bb777da5f61ce2ff29a774a0865a63ca [0.04 sec, 3.36 MB] [debug]
whatBootstrap to phase 0. [0.8 sec, 8.25 MB] [bootstrap]
Trying to bootstrap as far as we can. [0.82 sec, 8.26 MB] [debug]
Drush bootstrap phase : bootstrap_drupal_root() [0.85 sec, 8.65 MB] [bootstrap]
Initialized Drupal 8.0.3 root directory at /var/www/testproject/build/html [0.86 sec, 8.65 MB] [bootstrap]
Find command files for phase 1 (max=7) [0.87 sec, 6.47 MB] [debug]
Cache MISS cid: 8.1-dev-commandfiles-1-8ad2fc347e476a2ce9243705c49786b0 [0.87 sec, 6.47 MB] [debug]
Cache SET cid: 8.1-dev-commandfiles-1-8ad2fc347e476a2ce9243705c49786b0 [0.88 sec, 6.47 MB] [debug]
Drush bootstrap phase : bootstrap_drupal_site() [0.92 sec, 7.48 MB] [bootstrap]
Initialized Drupal site default at sites/default [0.92 sec, 7.49 MB] [bootstrap]
Find command files for phase 2 (max=7) [0.93 sec, 7.49 MB] [debug]
Drush bootstrap phase : bootstrap_drupal_configuration() [0.93 sec, 7.49 MB] [bootstrap]
Find command files for phase 3 (max=7) [0.94 sec, 7.71 MB] [debug]
5 1 2 sql-query: SELECT 1; [0.97 sec, 7.85 MB] [notice]
Executing: mysql --defaults-extra-file=/tmp/drush_mj4dGu --database=testproject --host=127.0.0.1 --silent < /tmp/drush_9jl8vX
1
5 1 2 sql-query: SHOW TABLES; [0.99 sec, 7.85 MB] [notice]
Executing: mysql --defaults-extra-file=/tmp/drush_Tj3s6y --database=testproject --host=127.0.0.1 --silent < /tmp/drush_VCMjT1
batch
block_content
block_content__body
block_content_field_data
block_content_field_revision
block_content_revision
block_content_revision__body
cache_bootstrap
cache_config
cache_container
cache_data
cache_default
cache_discovery
cache_entity
cache_menu
cache_toolbar
cachetags
comment
comment__comment_body
comment_entity_statistics
comment_field_data
config
file_managed
file_usage
flood
history
key_value
key_value_expire
menu_link_content
menu_link_content_data
menu_tree
node
node__body
node__comment
node__field_image
node__field_tags
node_access
node_field_data
node_field_revision
node_revision
node_revision__body
node_revision__comment
node_revision__field_image
node_revision__field_tags
paragraphs_item
paragraphs_item_field_data
paragraphs_item_revision
paragraphs_item_revision_field_data
queue
router
search_dataset
search_index
search_total
semaphore
sequences
sessions
shortcut
shortcut_field_data
shortcut_set_users
taxonomy_index
taxonomy_term_data
taxonomy_term_field_data
taxonomy_term_hierarchy
url_alias
user__roles
user__user_picture
users
users_data
users_field_data
watchdog
Drush bootstrap phase : bootstrap_drupal_database() [1.09 sec, 7.86 MB] [bootstrap]
Successfully connected to the Drupal database. [1.1 sec, 7.87 MB] [bootstrap]
Find command files for phase 4 (max=7) [1.1 sec, 7.87 MB] [debug]
Drush bootstrap phase : bootstrap_drupal_full() [1.11 sec, 7.87 MB] [bootstrap]
Cache MISS cid: 8.1-dev-install_profile-66ecfeb9791a023150773849f1550c5d [1.31 sec, 15.41 MB] [debug]
Cache SET cid: 8.1-dev-install_profile-66ecfeb9791a023150773849f1550c5d [1.31 sec, 15.41 MB] [debug]
Find command files for phase 5 (max=7) [1.31 sec, 15.42 MB] [debug]
Cache HIT cid: 8.1-dev-install_profile-66ecfeb9791a023150773849f1550c5d [1.32 sec, 15.42 MB] [debug]
Cache MISS cid: 8.1-dev-commandfiles-5-9ca671b9a0988e8d412bb1d31b8a7104 [1.37 sec, 16.78 MB] [debug]
Cache SET cid: 8.1-dev-commandfiles-5-9ca671b9a0988e8d412bb1d31b8a7104 [12.66 sec, 16.79 MB] [debug]
Drush bootstrap phase : bootstrap_drupal_login() [12.67 sec, 17.02 MB] [bootstrap]
Find command files for phase 6 (max=7) [12.76 sec, 20.54 MB] [debug]
Found command: core-status (commandfile=core) [12.77 sec, 20.54 MB] [bootstrap]
Loading outputformat engine. [13.71 sec, 24.29 MB] [notice]
Calling hook drush_core_status [13.73 sec, 24.35 MB] [debug]
5 1 2 Returned from hook drush_core_status [13.86 sec, 27.03 MB] [debug]
Drupal version : 8.0.3
Site URI : http://default
Database driver : mysql
Database hostname : 127.0.0.1
Database username : root
Database name : testproject
Drupal bootstrap : Successful
Drupal user :
Default theme : bartik
Administration theme : seven
PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini
PHP OS : Linux
Drush script : /var/www/testproject/vendor/drush/drush/drush.php
Drush version : 8.1-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Install profile : testprojectdotcom
Drupal root : /var/www/testproject/build/html
Drupal Settings File : sites/default/settings.php
Site path : sites/default
File directory path : sites/default/files
Temporary file directory path : /tmp
Sync config path : sites/default/files/config_4zDESHy66FpCFGJEy9L1lBPKsxp4bA_EJLhd_4xy8EiPszf62aSwJfPH9KHyOWvlejlm2nem-A/sync
Command dispatch complete [13.94 sec, 27.2 MB]
Without the -r
param:
vagrant ➜ testproject/build/html » drush --local -d status
Using the Drush script found at /var/www/testproject/vendor/drush/drush/drush.launcher using pcntl_exec
Cache HIT cid: 8.1-dev-commandfiles-0-bb777da5f61ce2ff29a774a0865a63ca [0.04 sec, 3.36 MB] [debug]
Bootstrap to phase 0. [1.09 sec, 8.18 MB] [bootstrap]
Trying to bootstrap as far as we can. [1.12 sec, 8.19 MB] [debug]
Found command: core-status (commandfile=core) [1.13 sec, 8.19 MB] [bootstrap]
Loading outputformat engine. [1.15 sec, 8.19 MB] [notice]
Calling hook drush_core_status [1.17 sec, 8.24 MB] [debug]
Returned from hook drush_core_status [1.18 sec, 8.25 MB] [debug]
PHP executable : /usr/bin/php
PHP configuration : /etc/php5/cli/php.ini
PHP OS : Linux
Drush script : /var/www/testproject/vendor/drush/drush/drush.php
Drush version : 8.1-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Command dispatch complete [1.25 sec, 8.42 MB]
That help at all?
I really appreciate you taking a look. I won't blame you at all if you have to just say "sorry, not sure what it could be"!
@mikecrittenden zipped up his codebase and sent it to me. I unzipped on my machine and drush works for me (OSX). WTF. @mikecrittenden is going to retry this codebase on a different machine.
This seems to just be a local environment quirk rather than a Drush issue, so I'm closing it.
I have the same issue, same exact directory setup (also using the grunt drupal tasks tool). I narrowed it down to our drush.wrapper script which was in our project root. It was cd
ing to the project root directory which made drush lose it's context of where the actual drush command was run. I modified as such:
# Get the full directory path of this drush.wrapper script
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
# Launch the project's drush
${DIR}/vendor/bin/drush.launcher --local "$@"
Seems to be the same as #2285
Wonder if this info would be good to comment there too.
Reopening since it doesn't seem to just be me. #2285 seems to be somewhat separate - that one is an issue of not being able to find the correct sites directory on a multi-site install, and this one is about not being able to find the Drupal codebase at all.
The docs in example/drush.wrapper say to put the file in project root the code suggests that drush.wrapper belongs in drupal root. So I do think there is a docs problem here. ping @greg-1-anderson .
What's actually confusing me a bit is that the drush.wrapper I have in an Acquia BLT project works fine and that has a CD in it:
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd "`dirname $0`"
if [ ! -f ${DIR}/vendor/drush/drush/drush.launcher ]; then
echo >&2 "Drush was not found in this project's vendor directory. You can install it by typing:"
echo >&2 "composer install"
exit 1
fi
vendor/drush/drush/drush.launcher --config=${DIR}/drush/drushrc.php --alias-path=${DIR}/drush/site-aliases "$@"
And in that project Drupal lives in docroot/
So now I'm unsure if my removal of cd
actually fixed the core problem or not...
We have the same issue here.
Might it be that when the "--root" parameter has been set in the drush.wrapper, this will propagate and not be overridden by the "--root" parameter in the alias?
That would explain "bkosborne commented on 13 Dec 2016".
What I see in our setup:
1. The wrapper file:
#!/usr/bin/env sh
cd "`dirname $0`"
deploy/htdocs/vendor/bin/drush.launcher --root=deploy/htdocs --local "$@"
2. A call to an alias with the wrapper results in [bad]:
The call:
$ cd /project-root
$ drush @alias status --verbose
Result:
Calling proc_open(ssh USER@SERVER 'env COLUMNS=121 /PROJECT_ROOT/deploy/htdocs/vendor/bin/drush --root=deploy/htdocs --local --verbose core-status --full 2>&1' 2>&1);
Notice that --root
is relative here and contains the value defined in the wrapper file.
I verified that this is always the value of the wrapper file that is used host/calling machine. So when I remove the wrapper on the alias-machine, that doesn't matter at all.
3. A call to an alias without the wrapper results in [good]:
The call:
$ cd /project-root
$ cd deploy/htdocs # go to drupal-root
$ drush @alias status --verbose
Result:
Calling proc_open(ssh USER@SERVER 'env COLUMNS=121 /PROJECT_ROOT/deploy/htdocs/vendor/bin/drush --verbose --root=/PROJECT_ROOT/deploy/htdocs core-status --full 2>&1' 2>&1);
Notice that --root
is absolute here.
Environment details We have Drush version 8.1.10 Drush is installed globally and in the project/vendor directory. Both on the calling machine (local) as on the server (where the alias is pointing to).
Yes, I think you correctly diagnosed the problem. The CLI always takes precedence over options provided via an alias. Not sure there is much we can do about that.
Aha. You can always run the command from the webroot and thereby skipping the wrapper file if you want to use aliases. Not sure if the wrapper file has any extra value then :|
Here's an example directory structure:
Let's imagine that the host machine has Drush 8 installed globally (the version of the project-bundled drush seems to be irrelevant).
If you
cd
intobuild/html
and rundrush status
(or any other Drush command) then what happens is that your global Drush (version 8) first tries to find a locally bundled Drush if one exists (see https://github.com/drush-ops/drush/blob/master/includes/startup.inc#L76). In our case, one does exist in/vendor/bin
.Once it finds that, it seems to decide that that is the new
root
andchdir
's to it (see https://github.com/drush-ops/drush/blob/master/includes/startup.inc#L281), and thus you lose the fact that you were running Drush from/build/html
and now it can't find Drupal anymore.Is this the desired behavior? It seems to mean that whenever you're using Drush 8 or 9 in a project where
/vendor/bin/drush
exists in a parent directory, then you ALWAYS have to include the--root
parameter for it to work, even if you're running Drush from the docroot in the first place.