Drupal 5 doesn't have a drush_backend_fork() anymore. I pin-pointed this to this commit:
http://drupalcode.org/project/drush.git/commitdiff/510735acb4a5e9a40f269...
I looked at the issue, and the removal of that function is first introduced in this patch:
http://drupal.org/node/1058874#comment-4552002
But there is no explicit reasoning and more importantly no explanation on how to replace function calls to that function.
I'd like to use Hostmaster with Drush 5 but drush hosting-dispatch fails with the following currently. There seem to be only 4 places in Hostmaster where this function is called, two of them in an API file (http://drupalcode.org/project/hostmaster.git?a=search&h=HEAD&st=grep&s=d...) so it shouldn't be a huge amount of work. I don't know if there is anything else to do for Drush 5 compatibility, though.
I'd be happy to supply a patch, I just need to know what to do :)
Thanks.

Comments

tstoeckler’s picture

Oops, here's the error message:

PHP Fatal error: Call to undefined function drush_backend_fork() in /var/aegir/
hostmaster-6.x-1.6/profiles/hostmaster/modules/hosting/dispatch.hosting.inc on l
ine 44

steven jones’s picture

Project: Hostmaster (Aegir) » Drush
Version: 7.x-2.x-dev »
Component: Code » Base system (internal API)

Agreed, moving to the Drush queue for more visibility, could you advise as to what the replacement for the drush_backend_fork function is? And then could you move it back into our Hostmaster queue please?

Thanks!

tstoeckler’s picture

Title: Make hosting (specifically hosting-dispatch) work with Drupal 5 » Make hosting (specifically hosting-dispatch) work with Drush 5

Wow, major brainfail.
Fixing title.

greg.1.anderson’s picture

Project: Drush » Hostmaster (Aegir)
Version: » 7.x-2.x-dev
Component: Base system (internal API) » Code

The changes quoted above were part of a series of very large changes to backend invoke to support Windows (spaces in filenames) and concurrent execution of multiple commands (drush_backend_invoke_concurrent).

I suggest that the first thing that you do is change all of your code that uses drush_backend_fork to instead call drush_process_invoke. This will give you spaces-in-filenames compatibility, but you will lose the "fork" capability, as the command will not return control to you until it has completed execution.

Once you get to that point, I suggest that we add a new item to $backend_options, 'fork' => TRUE. So, your call to drush_invoke_process would look like this:

 $values = drush_invoke_process($site, $command, $args, $options, array('fork' => TRUE));

n.b. previously, there were $hostname and $username parameters to the backend functions; now you're going to want to pass $site = array('remote-host' => $hostname, 'remote-user' => $username) instead.

Then we can re-add the missing fork capability to Drush. If we can work through this quickly enough, there is a plan to release Drush-5RC1 and Drush-4.6 sometime this week. It would be nifty to get this patch in both releases, as then you could have one call that worked on both versions of Drush. Maybe that won't turn out to be feasible, but it's good to have goals. :)

I will monitor this issue and help out with the Drush tasks.

greg.1.anderson’s picture

tstoeckler’s picture

Status: Active » Postponed

That's awesome, thanks.

As a stop-gap fix I tried simply replacing drush_backend_fork() with drush_invoke_process() in the way you explained, but then Aegir hangs indefinitely on the process, so it seems the 'forking' part actually isn't happening. That said, I am a super-noob in this entire field of command-line-processing, so it might be something on my system...

EDIT: The actual reason for my post was marking this postponed on the Drush issue...

anarcat’s picture

Priority: Normal » Critical
Status: Postponed » Active

I think what greg meant here is that drush_invoke_process() needs to be modified so that it *can* fork, which is not currently the case. :)

Let's keep this opened. Drush 5 support is an explicit goal of the 2.x release and we should help Drush here, not just wait. :)

greg.1.anderson’s picture

Yes, #7 is correct. If you could post the patch from #6, then perhaps others can participate in making Drush and Aegir work together correctly once I have a patch posted on the Drush issue.

tstoeckler’s picture

StatusFileSize
new1.94 KB

Here's the patch I used. For some reason there is no drush_backend_fork in hosting.queues.inc locally for me, even though drupalcode.org says there is. Didn't investigate that yet.

Just as a heads-up: I'm willing to put some time into this, including the Drush issue, in terms of (re-)rolling patches, search&replace stuff, etc. So just tell me what to do :). I just won't be of any substantial help, because this is just way over my head.

greg.1.anderson’s picture

Instead of:

drush_backend_fork('@self', "hosting-" . $queue, array(), array('items' => $count));

Try:

drush_invoke_process('@self', "hosting-" . $queue, array(), array(), array('items' => $count), array('fork' => TRUE));

This presumes you would like to run: drush hosting-$queue --items=$count &.

Instead of:

drush_invoke_process('@self', "hosting-task", array($task->nid));

Try:

drush_invoke_process('@self', "hosting-task", array($task->nid), array(), array('fork' => TRUE));

This presumes you would like to run: drush hosting-task $task->nid &.

Please forgive the blending of bash and php syntax above. Test with #1433556: Aegir wants the drush_backend_fork capability restored..

tstoeckler’s picture

Awesome stuff! Man, you are super-quick!!!

Re-rolled for the above and also found the stray drush_backend_fork() (I was grepping the wrong branch before...).

Will try it out now.

tstoeckler’s picture

Now getting fatal: Undefined function drush_backend_invoke_args()
It should be possible to replace that with drush_invoke_process(), too, though, right?

tstoeckler’s picture

Yes, that seemed to have worked. The process now runs through, successfully I guess.
At least I get the whole proper output for the task (a simple verify task), but even though it says
"Command dispatch complete" at the bottom of the list the status is still "Processing". Hmm...
BTW: I'll probably go to bed soon-ish but I'm still in IRC for like an hour I guess, so...

greg.1.anderson’s picture

Yes, drush_backend_invoke_args was removed in favor of drush_invoke_process. Just post the old code here if you have any question about how to map the args from one function to the new one.

tstoeckler’s picture

Well, I think I got it right:

// Before
drush_backend_invoke_args('provision-save', array('@' . $task->ref->hosting_name), $task->context_options, $mode);

// Now
drush_invoke_process('@self', 'provision-save', array('@' . $task->ref->hosting_name), $task->context_options, array('method' => $mode));

Updating the patch right now.

Is there some exhaustive list of functions that are now deprecated by drush_invoke_process()? Rolling the patch above I saw a drush_backend_invoke() somewhere and a quick search revealed, that was removed also...

EDIT: Weird syntax error in the PHP code.

greg.1.anderson’s picture

#15 looks right to me.

drush_invoke_process() replaces most of the old methods for calling drush commands from drush commands. Only drush_invoke() and drush_dispatch() remain, but those were used only in special cases. Most drush_invoke_* and drush_backend_* calls should become drush_invoke_process.

tstoeckler’s picture

Updated patch.
Sorry for the spam, but I realized that the above patch is wrong (I test this on a 6.x-1.6 aegir, so am doing the changes manually, because the patch doesn't apply.), so if anyone is following along, #11 will fail hard.

BTW: Remaining functions in hostmaster that are in the "drush_backend_" namespace are drush_backend_output() and drush_backend_invoke().

tstoeckler’s picture

StatusFileSize
new4.13 KB

Damn. Sorry again. It's late here...

greg.1.anderson’s picture

drush_backend_output works the same in Drush-5 as it did in Drush-4. drush_backend_invoke should be replaced with drush_invoke_process, but be careful with this one, as drush_backend_invoke allowed you to put the command name, options and args into a single string that was exploded on space. drush_invoke_process does not allow this.

anarcat’s picture

I just wanted to say that you guys are doing amazing work and I'm really happy to see people undertake this important task! Keep it up, can't wait to see 2.x actually "compile" with Drush 5. :)

greg.1.anderson’s picture

tstoeckler’s picture

StatusFileSize
new4.13 KB

That is awesome, thanks!

For now, drush_backend_fork() is missing from that list, don't know if that is intentional, because the 'fork' doesn't exist yet.

This patch covers everything on that list. It's basically the same patch as above, except there was one drush_backend_invoke() left in the docs.

Will now start playing around with the Drush patch and see if I can get this to work...

thedavidmeister’s picture

When I run "$ drush update" I now see a notice telling me that I should upgrade my version of drush to 5.1 as it is the new "recommended" version. Considering that this instantly breaks Aegir and prevents it from running cron tasks with no visible notice or warning displayed to the user, the recommendation strikes me as kind of silly, but that's the way things are.

This issue is already flagged as critical, but I just wanted to re-iterate that the situation kind of sucks atm. I wish I could offer a patch, but I don't think I'll be able to for this one.

fizk’s picture

Category: task » bug

I agree with thedavidmeister.

I'd also like to say that every time I try my luck at installing Aegir (i.e. "let's see if I can get it to work this time"), it fails miserably.

The testing and release process of Aegir needs to be improved a great deal.

Also, because of the heavy dependency on Drush, the Aegir team should strive to publish new releases to be compatible with each new Drush release. For example, run automated testing for each new git commit in the Drush repository.

steven jones’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Active » Needs review

We are trying to fix this for 2.x

thedavidmeister’s picture

In the meantime, it looks like it is totally ok to put drush5 into a separate folder in your user's directory and alias it in your bashrc or bash_profile. That way you can at least get the latest features through the cli so even if Aegir doesn't get the benefit of caching, etc..

Something as simple as this (assuming you extracted drush5 into ~/drush5):

alias drush5='~/drush5/drush'

webmaster-eddie’s picture

Version: 6.x-2.x-dev » 6.x-1.9

Hello,

I inadvertently upgraded a working drush 4.5 to 5.2 (by running pecl upgrade - and there was no opportunity to say "no"). Now aegir sees my dush version as 5.2 and debian as 4.5. Con no longer runs, and I am unable, believe it or not, to downgrade drush to 4.5. Are there any downgrade guides for aegir. Don't use version control yet - will have to start that now, I see.

I am contemplating modifying the aegir hostmaster upgrade.sh script and trying to upgrade from 6.19 to 6.19 and hopefully that process will give me an opportunity to choose drush 4.5 during that process. Any ideas on if this should work and if it might destroy aegir hosting platform. Unfortunately this is on a production server. I am an aegir / drush relative newbie.

Otherwise, do you recommend me applying the patch in comment # 22, above, and that should allow drush 5.2 to be properly functional, which might then allow me to downgrade it to 4.5.

OR

Any easy way to just downgrade drush (in aegir) to 4.5 without touching the aegir and hostmaster packages?

Thanks for any advice and help here.

Eddie

steven jones’s picture

Version: 6.x-1.9 » 6.x-2.x-dev

We would recommend restoring the previous version of Drush. If it came from packages, then removing the newer version of drush would be a good first step, then running something like:

sudo apt-get install --reinstall drush

Should re-install the old version of Drush.

In the future please raise support issues like this in new issues and don't hijack existing ones!

anarcat’s picture

Status: Needs review » Fixed

It seems that this patch was merged in, so I am not sure why this is still marked as opened. This just works now.

anarcat’s picture

@tstoeckler & @greg.1.anderson - it would be useful if you could take a look at #1612042: hosting-dispatch throws loads of garbage when running in drush 5, where I see a lot of garbage coming out of hosting-dispatch, even without the -v or -d flags...

tstoeckler’s picture

Cool, I'll have to check that.
Last time I tried this patch it didn't actually work, so...
...but all the better if it works now. :)

Status: Fixed » Closed (fixed)

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

socialnicheguru’s picture

Version: 6.x-2.x-dev » 6.x-1.9
Status: Closed (fixed) » Active

I am getting this error after installing aegir 1.9
I got a message in my logs
ran drush '@hostmaster' hosting-dispatch --debug

PHP Fatal error: Call to undefined function drush_backend_fork() in /var/aegir/hostmaster-6.x-1.9/profiles/hostmaster/modules/hosting/dispatch.hosting.inc on line 44

Fatal error: Call to undefined function drush_backend_fork() in /var/aegir/hostmaster-6.x-1.9/profiles/hostmaster/modules/hosting/dispatch.hosting.inc on line 44
Drush command terminated abnormally due to an unrecoverable error. [error]
Error: Call to undefined function drush_backend_fork() in
/var/aegir/hostmaster-6.x-1.9/profiles/hostmaster/modules/hosting/dispatch.hosting.inc,
line 44 [0.76 sec, 34.3 MB]

patch does not apply cleanly:

aegir@:~/hostmaster-6.x-1.9/profiles/hostmaster$ patch -p1 < 14*
patching file modules/hosting/dispatch.hosting.inc
patching file modules/hosting/hosting.api.php
Hunk #1 succeeded at 298 (offset 35 lines).
Hunk #2 succeeded at 316 (offset 35 lines).
patching file modules/hosting/task.hosting.inc
Hunk #1 succeeded at 101 (offset -3 lines).
Hunk #2 succeeded at 112 (offset -3 lines).
patching file modules/hosting/task/hosting_task.module
Hunk #1 FAILED at 498.
1 out of 1 hunk FAILED -- saving rejects to file modules/hosting/task/hosting_task.module.rej
aegir@:~/hostmaster-6.x-1.9/profiles/hostmaster$ modules/hosting/task/hosting_task.module.rej
-su: modules/hosting/task/hosting_task.module.rej: Permission denied

aegir@devmac:~/hostmaster-6.x-1.9/profiles/hostmaster$ more modules/hosting/task/hosting_task.module.rej
--- modules/hosting/task/hosting_task.module
+++ modules/hosting/task/hosting_task.module
@@ -498,7 +498,7 @@
drush_log(dt("Running tasks queue"));
$tasks = _hosting_get_new_tasks($count);
foreach ($tasks as $task) {
- drush_backend_fork("hosting-task", array($task->nid));
+ drush_invoke_process('@self', "hosting-task", array($task->nid), array(), a
rray('fork' => TRUE));
}
}

other files that call drupal_backend_fork
hosting/hosting.queues.inc:174: drush_backend_fork("hosting-task", array($task->nid));

Edit: Solved by downgrading to 4.6

steven jones’s picture

Version: 6.x-1.9 » 6.x-2.x-dev
Status: Active » Closed (fixed)

Yeah, so at the moment the 1.x branch is compatible with Drush 4, and the 2.x branch is compatible with Drush 5, we are trying to get a stable release for 2.x done this year.