Hi, I would like to create a script to get the module status from every site in a multi-site install. This probably isn't too hard, I could just manually run drush statusmodules on each site, and then run it through a separate script. I'm just wondering if that's the best way to go about it. Seems like a fairly big database hit, but maybe that's just a fact of life.

There are number of other modules that interface with drush. Is there an API for this? I can't find any documentation. Would it make sense to create a drupal module to interface with drush for this kind of stuff? Perhaps it would make sense to converte Multisite Maintenance to interface with drush instead of doing it's own thing?

Comments

Brian@brianpuccio.net’s picture

Status: Active » Fixed

Since the modules might vary from site to site in a multisite install, it seems to me you'd have to hit each site's database. From the BASH Programming - Introduction HOW-TO:

        #!/bin/bash
        for i in $( ls ); do
            echo item: $i
        done

So do an ls in your sites directory and instead of echoing them, run the drush module status command with the site passed as an argument for each one.

Looking through the multisite_api (specifically function multisite_api_site_list), which the multisite_maintenance module relies upon, it seems all it does is find a listing of all sites (or more accurately settings.php files), so that doesn't seem to be any faster than the above. Feel free to re-open if you think otherwise since I don't consider myself to be the ultimate authority on this. I just don't think you'll be ale to get around having to parse the database authentication info in each site's settings.php, which drush does, and then hitting the modules in each site's database sequentially.

naught101’s picture

Status: Fixed » Active

Hrmm... that wasn't very well thought through on my part. I've already written a script like that. But there's still the second part of my question:

Having looked at devel and drush a bit, I now see that modules with "drush integration" provide commands for drush to use.

I'm wondering if it's possible to do it the other way - ie. call drush from within drupal (to gather information), and then display that information within drupal? In otherwords, does drush (or will drush ever) provide an interface for drupal/drupal modules to hook into?

Brian@brianpuccio.net’s picture

Assigned: Unassigned » Brian@brianpuccio.net

Yes, you can call drush from within your modules, Aegir does this a lot. See also #349923: drush_invoke : a flexible API for hooking into any and all drush calls..

moshe weitzman’s picture

Alas, there is no reliable way for drupal to introspect and find all these base urls. Most sites use an implicit base url based on the incoming domain of the request. So admin will need to maintain a list of base urls in .drushrc.php file. Once we have that, we could support a --multisite param for any drush command. when that is present, it would iterate over the list and run the same command for all sites. i guess it would accumulate the output from each and show you a nice table at the end. i'd love adrian and owen's opinion on this idea.

naught101’s picture

Are there docs anywhere for drush_invoke?

Brian@brianpuccio.net’s picture

Drupal Contrib API to start and then follow some aegir examples, that's all I know of.

naught101’s picture

Moshe: you could auto-generate the list from all sites/<site>/ directories with working settings.php files in them, right?

naught101’s picture

Moshe: re: a reliable way to get base URLs: The Multisite API module does something like what I just described.

There's also the multisite_modules sub-module of Multisite Maintenance module, which does exactly as I want (I coded a large part of it), but it's for drupal5, and is fairly hackish. I'd much rather try to create a more robust, re-usable solution, preferably as part of a more active project.

I'm thinking that it might be possible to create a Multisite API drush.inc, but it might be better to move some of the core Multisite API into drush (and possibly even re-write some of the multisite maintenance so that it uses drush_invoke?).

I'll let dalin know about this thread.

moshe weitzman’s picture

Interesting. I'm pretty sure that this requires explicitly stating a base_url in settings.php which is unusual and a bit inconvenient. Maybe we could do our best guess thing based on directory name.

dalin’s picture

It's always been in the back of my mind to integrate Multisite API with Drush.

Moshe you are correct about $base_url, if $base_url is not explicitly defined, then the directory name may or may not be the $base_url. It won't be if the site:
- uses the default sites directory
- is on a special port
- is in a subdirectory of the domain, or
- the directory name is only a partial match to the $base_url (ex. foo.bar.example.com => sites/example.com/)

Currently Multisite API only returns $base_url if it is explicitly defined. In the documentation I describe this reverse engineering problem. What we could do is have Multisite API return an additional variable, $base_url_derived or the like which would be our "best guess".

I have a long flight on Monday, I might be able to take a closer look at this then.

naught101’s picture

Dalin: where is the documentation that describes the $base_url reverse engineering problem? I'm trying and failing to get my head around it.

Wouldn't it be possible to overcome #2 and #4 with strtolower($_SERVER['SERVER_NAME'])? And if wouldn't it be safe to assume #1 if that string didn't match any appropriate sites folders?

greg.1.anderson’s picture

$_SERVER['SERVER_NAME'] is set by Drush, so depending on that is circular logic...

The $base_url reverse engineering problem is still an issue, but some of the problems touched on in this issue are addressed by site aliases and #628996: Concurrently execute a single drush command on multiple sites.

moshe weitzman’s picture

Status: Active » Closed (works as designed)

I think we can discuss more at #628996: Concurrently execute a single drush command on multiple sites. Or reopen this with some clarification about how this issue is different.

naught101’s picture

Good enough for me..