drush icon indicating copy to clipboard operation
drush copied to clipboard

Boostrap failing with Drush 9.1.0

Open adriancotter opened this issue 8 years ago • 26 comments

I had drush 9 working before it got upgraded to 9.1.0 and am a little bit at my wits end why bootstrap is failing and why I get "Bootstrap failed" or "! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands."

  • My build directory is separate from my vendor directory. (shorthanded below to [build] and [composer]
  • There are a couple debugged commands below, one trying to use an alias, and one just using the help command.
  • There are a couple extra alias paths (the last two) which are not valid and I can't figure out where they come from (they are not in my drush.yml anywhere), but my alias file is found... @default.dev does seem to work.
  • adding -r or -uri (or using that in place of the alias) does not make any difference... I still get the Bootstrap failed.

What has changed or earlier versions of Drush 9, or what am I doing incorrectly here? There was similar things with Drush 8 at some point, but none of the solutions that I saw in there worked, and I didn't see anything specific to Drush 9.

Thanks for your help.

[794e@794elmp01 htdocs]$ drush @default.dev cr -d
 [preflight] Config paths: /../.drush/drush.yml,/var/..[composer]/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /../.drush/sites,/var/..[build]/sites,/var/..[build]/drush/sites,/var/..[composer]/drush/sites
 [preflight] Commandfile search paths: /var/../vendor/drush/drush/src
 [bootstrap] Bootstrap to site [0.2 sec, 10.19 MB]
  [Exception]
  Bootstrap failed.
Exception trace:
 () at /var/..[composer]/vendor/drush/drush/src/Boot/BootstrapHook.php:31
 Drush\Boot\BootstrapHook->initialize() at /var/..[composer]/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:34
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->callInitializeHook() at /var/..[composer]/vendor/consolidation/annotated-command/src/Hooks/Dispatchers/InitializeHookDispatcher.php:27
 Consolidation\AnnotatedCommand\Hooks\Dispatchers\InitializeHookDispatcher->initialize() at /var/..[composer]/vendor/consolidation/annotated-command/src/CommandProcessor.php:117
 Consolidation\AnnotatedCommand\CommandProcessor->initializeHook() at /var/..[composer]/vendor/consolidation/annotated-command/src/AnnotatedCommand.php:391
 Consolidation\AnnotatedCommand\AnnotatedCommand->initialize() at /var/..[composer]/vendor/symfony/console/Command/Command.php:229
 Symfony\Component\Console\Command\Command->run() at /var/..[composer]/vendor/symfony/console/Application.php:859
 Symfony\Component\Console\Application->doRunCommand() at /var/..[composer]/vendor/symfony/console/Application.php:206
 Symfony\Component\Console\Application->doRun() at /var/..[composer]/vendor/symfony/console/Application.php:125
 Symfony\Component\Console\Application->run() at /var/..[composer]/vendor/drush/drush/src/Runtime/Runtime.php:112
 Drush\Runtime\Runtime->doRun() at /var/..[composer]/vendor/drush/drush/src/Runtime/Runtime.php:41
 Drush\Runtime\Runtime->run() at /var/..[composer]/vendor/drush/drush/drush.php:64
 require() at /var/..[composer]/vendor/drush/drush/drush:4
drush list -d
 [preflight] Config paths: /home/794e/.drush/drush.yml,/var/..[composer]/vendor/drush/drush/drush.yml
 [preflight] Alias paths: /home/794e/.drush/sites,/var/..[build]/sites,/var/..[build]/drush/sites,/var/..[composer]/drush/sites
 [preflight] Commandfile search paths: /var/..[composer]/vendor/drush/drush/src
 [bootstrap] Bootstrap to max [0.22 sec, 10.14 MB]
 [debug] Trying to bootstrap as far as we can [0.22 sec, 10.15 MB]
Drush Commandline Tool 9.1.0
! [NOTE] Drupal root not found. Pass --root or a @siteAlias in order to see Drupal-specific commands.

adriancotter avatar Feb 23 '18 01:02 adriancotter

Also, addiitonal info: this is the site reference in the default.site.yml

dev:
  root: /var/..[build]/htdocs
  uri: http://dev.our.internal.url.com

I verified the root and URI were correct... and that the URI was accessible from the server (it is not a public URI)

adriancotter avatar Feb 23 '18 02:02 adriancotter

Please use Drupal Answers for support questions.

weitzman avatar Feb 24 '18 16:02 weitzman

I have posted it there as per your request, but the thing feels relevant for this forum is that Drush 9 was properly bootstrapping when I was using beta8. This problem only occurred when composer upgraded to _1_0. https://drupal.stackexchange.com/questions/256526/boostrap-failing-with-drush-9-1-0

I waited to add to this until I could try it. And I have confirmed this just now by returning to beta8, and I am now bootstrapped correctly...

I'll see if I can't move up through the releases to see where it stops working exactly, but if you had any obvious thoughts that seems like it would be helpful.

Thanks for all your work, and sorry to be a pain, Adrian

$ drush st
 Drupal version   : 8.4.5
 Site URI         : ****
 DB driver        : mysql
 DB hostname      : ****
 DB port          :
 DB username      : dev_***
 DB name          : dev_***
 Database         : Connected
 Drupal bootstrap : Successful
 Default theme    : bartik
 Admin theme      : seven
 PHP binary       : /usr/bin/php
 PHP config       : /etc/php.ini
 PHP OS           : Linux
 Drush script     : /var/[composer]/vendor/bin/drush
 Drush version    : 9.0.0-beta8
 Drush temp       : /tmp
 Drush configs    : /home/../.drush/drush.yml
                    /var/[composer]/vendor/drush/drush/drush.y
                    ml
 Drush aliases    :
 Install profile  : standard
 Drupal root      : /var/[build]/htdocs
 Site path        : sites/*
 Files, Public    : sites/*/files
 Files, Temp      : /tmp

adriancotter avatar Feb 26 '18 19:02 adriancotter

Could you use git bisect to find out which commit broke bootstrapping for your configuration? Off the top of my head, I can't think of any site selection behavior changes that would cause this, but some changes to the preflight and bootstap have been made. Knowing the commit would be helpful to finding a solution.

greg-1-anderson avatar Feb 26 '18 19:02 greg-1-anderson

Thanks Greg, I am working on that now.

adriancotter avatar Feb 26 '18 19:02 adriancotter

Worked with

  • 9.0.0-beta8
  • 9.0.0-beta9
  • 9.0.0-rc1

Failed at

  • 9.0.0-rc2

Let me know how I could be helpful in tracking it down further (there's a lot in that release!)

adriancotter avatar Feb 26 '18 19:02 adriancotter

We have docs about how to use bisect to find the exact commit that introduces a failure. See https://raw.githubusercontent.com/drush-ops/drush/master/examples/git-bisect.example.sh. Not sure though that --strict=2 works as before, and also composer install is needed after each code change.

weitzman avatar Feb 26 '18 19:02 weitzman

--strict=2 is not supported in Drush 9. Not needed for this in any event.

greg-1-anderson avatar Feb 26 '18 20:02 greg-1-anderson

Thanks for the doc, and having trouble getting this working. Conceptually though -- and sorry to be dense, this is a new command for me -- if I am not pulling the drush code from git directly, how is this working exactly?

adriancotter avatar Feb 26 '18 21:02 adriancotter

@adriancotter You must clone the Drush repository from GitHub in order to use git bisect.

greg-1-anderson avatar Feb 26 '18 22:02 greg-1-anderson

Whew successful pushing of my git/composer capabilities... This is the result I got back bisecting between c90592629c5a2539c6f381f874f3ce4c221ee539 and 20360f1c590f53a196e971b180c91b625eb9ed98

7b698ef4683d9d642413658b650bf42ab8ed385d is the first bad commit
commit 7b698ef4683d9d642413658b650bf42ab8ed385d
Author: Matthew Grasmick <[email protected]>
Date:   Thu Dec 14 14:28:45 2017 -0500

    #3110: Prevent infinite loops in RedispatchToSiteLocal. (#3235)

In that commit, if I reverse the change in src/SiteAlias/AliasRecord.php things work again.

The only thing I notice (when I run drush st) that seems related is that Drupal root : /var/[composer]/../../../sc-sites-d8/htdocs isn't "realpathed" so I wonder if this path was failing with the FsUtils::realpath in Grasmick's commit, but running it on the command line, it worked correctly. Any thoughts?

adriancotter avatar Feb 27 '18 00:02 adriancotter

Do you have any paths with /../ in your drush.yml file? Maybe you could try using absolute paths here instead and see if that works better.

I am not sure why this change broke your configuration; maybe there's one (or more) places that still need the realpath transformation.

greg-1-anderson avatar Feb 27 '18 00:02 greg-1-anderson

Nope. The paths in my drush.yml are absolute.

adriancotter avatar Feb 27 '18 01:02 adriancotter

So, you said that if you reverse the change in src/SiteAlias/AliasRecord.php it works again. What is that add before/after print statements to that function that fire iff the parameter is changed. What is the last path pair printed in the failing scenario?

greg-1-anderson avatar Feb 27 '18 01:02 greg-1-anderson

I had already started in on that. The starting path has a relative path within it /var/dev/composer/htdocs/a/../../../web/htdocs

When it fails, the path has been successfully converted to a non-relative version. /var/dev/web/htdocs

It gets called 3 times. Same thing each time. Both paths work in the command line. I don't know why the non-relative one would be the one to fail. Getting parsed somewhere where its expecting the relative bits?

adriancotter avatar Feb 27 '18 01:02 adriancotter

Where is htdocs/a coming from? Maybe try using FSUtils::realpath() on $root in SiteAliasManager::buildSelf().

greg-1-anderson avatar Feb 27 '18 14:02 greg-1-anderson

Okay, I found the problem, or found the reason that the problem is happening with the realpath change. And that is in DrupalFinder isValidRoot function. https://github.com/webflo/drupal-finder/blob/master/src/DrupalFinder.php

  • DrupalFinder before it looks for a the core common code, checks for the existence of composer.json in whatever directory it is looking at... I'm not sure why it is doing this, because at least in my setup, there is not json file in this root.
  • It WORKS when the path has the relative bit in it (before the FSUtils:realpath was added), because DrupalFinder is just parsing through the path... so with /var/dev/composer/htdocs/a/../../../web/htdocs it eventually finds /var/dev/composer/htdocs/a/composer.json, but does not find the core code in that directory.
  • I was able to get it working by dropping an empty composer.json file in the root of my build directory.

So maybe there is still some issue with my setup in that I don't have a composer file in that directory, but I didn't think I was doing anything that unusual...

[Edit]: I see that if I download Drupal from drupal.org I get a composer.json file -- but that does not seem to be present when Composer builds Drupal 8?

adriancotter avatar Feb 27 '18 19:02 adriancotter

Thanks for debugging this. That was a difficult session I'm sure.

Can you elaborate on My build directory is separate from my vendor directory.? Are you using Composer env variables to accomplish this? Whats your composer.json, environment vars, and final folder layout look like? This is starting to look like a Drupal-Finder issue but OK to discuss here.

weitzman avatar Feb 27 '18 20:02 weitzman

So my Drupal Core & module file directories are defined in the "extra" "installer-paths" I haven't set any environmental variables that I know of. The puzzling thing to me is if the composer.json should be there or not... I don't think I am doing anything that would exclude it from being there...

{
    "name": "drupal-composer/drupal-project",
    "description": "",
    "type": "project",
    "license": "GPL-2.0+",
    "authors": [
        {
            "name": "",
            "role": ""
        }
    ],
    "repositories": [
        {
            "type": "composer",
            "url": "https://packages.drupal.org/8"
        }
    ],
    "require": {
        "composer/installers": "^1.2",
        "cweagans/composer-patches": "^1.6",
        "drupal-composer/drupal-scaffold": "^2.2",
        "drupal/bootstrap": "^3.9",
        "drupal/console": "^1.0.2",
        "drupal/core": "~8.4",
        "drupal/paragraphs": "^1.2",
        "drush/drush": "~8.0|^9.0.0-beta8",
        "webflo/drupal-finder": "^1.0.0",
        "webmozart/path-util": "^2.3"
    },
    "require-dev": {
        "behat/mink": "~1.7",
        "behat/mink-goutte-driver": "~1.2",
        "jcalderonzumba/gastonjs": "~1.0.2",
        "jcalderonzumba/mink-phantomjs-driver": "~0.3.1",
        "mikey179/vfsstream": "~1.2",
        "phpunit/phpunit": ">=4.8.28 <5",
        "symfony/css-selector": "~2.8|~3.0"
    },
    "conflict": {
        "drupal/drupal": "*"
    },
    "minimum-stability": "stable",
    "config": {
        "sort-packages": true
    },
    "autoload": {
        "classmap": [
            "scripts/composer/ScriptHandler.php"
        ]
    },
    "scripts": {
        "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
        "pre-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "pre-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::checkComposerVersion"
        ],
        "post-install-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ],
        "post-update-cmd": [
            "DrupalProject\\composer\\ScriptHandler::createRequiredFiles"
        ]
    },
    "extra": {
        "installer-paths": {
            "../../../[build]/core": ["type:drupal-core"],
            "../../../[build]/libraries/{$name}": ["type:drupal-library"],
            "../../../[build]/modules/contrib/{$name}": ["type:drupal-module"],
            "../../../[build]/profiles/contrib/{$name}": ["type:drupal-profile"],
            "../../../[build]/themes/contrib/{$name}": ["type:drupal-theme"],
            "drush/contrib/{$name}": ["type:drupal-drush"]
        }
    }
}

adriancotter avatar Feb 27 '18 23:02 adriancotter

I just created a fresh composer project using this composer create-project drupal-composer/drupal-project:8.x-dev testing --stability dev --no-interaction And found that no composer.json file is created there

So not sure why this is not problematic for others -- while looking for core files, the $path is checked for autoload.php (which is there) and composer.json (which is not)

if (!empty($path) && is_dir($path) && file_exists($path . '/autoload.php') && file_exists($path . '/' . $this->getComposerFileName())) {
            $candidate = 'core/includes/common.inc';
            if (file_exists($path . '/' . $candidate) && file_exists($path . '/core/core.services.yml')) {
```
It is an easy solution to slap a composer.json file in there, but not sure if I should have a particular composer.json or if the drupal project should have one...

adriancotter avatar Feb 28 '18 01:02 adriancotter