On Acquia Cloud, the Drush background import check that runs on /admin/content/migrate/configure fails even with $conf['migrate_drush_path'] configured correctly to /usr/local/bin/drush. I stepped through the code below with Devel from inside a site, and noticed that the "drush status" that is run returns most information, but does not return a proper "Drupal bootstrap: Successful", which is what the code is checking for. When I output the value of $command, and run it directly on the server, it does output "Drupal bootstrap: Successful" as it should.

I was not able to figure out why the output did not include the bootstrap info when run from the site, so it's unclear if it's something with Acquia or something that can be fixed in this code. I opened a support ticket with Acquia (#230646) about this and they verified the background migrate task worked. The migration appears to be able to be run in the background, it's just that the check makes it appear to be configured incorrectly in the UI.

The snippet below is where the check happens, and causes $drush_validated to still be FALSE, and report that "Drush is misconfigured on the server". Thanks!

  if ($drush_path && is_executable($drush_path)) {
    // Try running a drush status command to verify it's properly configured.
    $uri = $GLOBALS['base_url'];
    $uid = $GLOBALS['user']->uid;
    $command = "$drush_path status --user=$uid --uri=$uri --root=" . DRUPAL_ROOT;
    exec($command, $output, $status);
    if ($status == 0) {
      $version = '';
      foreach ($output as $line) {
        if (preg_match('|Drush version +: +(.*)|', $line, $matches)) {
          $version = trim($matches[1]);
        }
        elseif (preg_match('|Drupal bootstrap +: +Successful *|', $line, $matches)) {
          $drush_validated = TRUE;
        }
      }
    }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vinmassaro created an issue. See original summary.

vinmassaro’s picture

Issue summary: View changes
vinmassaro’s picture

Status: Active » Needs review
FileSize
1.82 KB

I received this response from Acquia support (#242926):

The reason Drush does not bootstrap is because it requires several environment variables that our platform sets when you are running as the site.environment user. Running from PHP, those environment variables are not set, and so the bootstrap fails.

That being said, there is a workaround that may allow the drush commands to work going through the UI. When you login via SSH, a shell script is run that sets the environment variables. If you manually run that script in the same line of code that you run Drush in, the environment variables should be set and the bootstrap will be successful.

Attached is a patch that fixes this issue by checking if the AH_SITE_ENVIRONMENT environment variable is set, and adding the script prefix before the drush command. I've tested it on Acquia Cloud and am able to run migrations in the background from the UI.

vinmassaro’s picture

New patch with updated comment.

pifagor’s picture

Status: Needs review » Reviewed & tested by the community

  • pifagor committed 665fc6c on 7.x-2.x authored by vinmassaro
    Issue #2599200 by vinmassaro, pifagor: Drush background operations check...
pifagor’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

joseph.olstad’s picture