Performing DRD actions from Drush: Drupal power tools, part 2 of 4

Drupal Remote Dashboard (DRD) fully supports Drush and it does this in two ways: DRD provides all its actions as Drush commands and DRD can trigger the execution of Drush commands on remote domains. This blog post is part of a series (see part 1 of 4) that describes all the possibilities around these two powerful tools. This is part 2 which describes on how to trigger any of DRD's actions from the command line by utilizing Drush.

Why is this useful? A lot of admins and devops are keyboard junkies and they kind of hate the idea to monitor and manage their Drupal server farm by clicking around in DRD's UI. All of DRD's power is now back to the terminal and extending on that idea, this helps to automate all of DRD's action by using Drush in crontabs, e.g. to check for updates on all domains on all Drupal cores in an entire network.

Prerequisites

If DRD (version 2.4 or later) is installed and configured on your main Drupal core which is monitoring all your other Drupal cores, then you only need Drush on that same host and access to the console. That's all you need to get access to all the nice stuff described below.

Get a list of DRD's drush commands

drush help --filter=drd

All commands in drd: (drd)
  drd-action (drda):        Trigger a DRD action.
  drd-list-actions (drdla): List all the available actions for your DRD network.
  drd-list-cores (drdlc):   List all cores in your DRD network.
  drd-list-domains (drdld): List all domains for all or some DRD cores.
  drd-list-tags (drdlt):    List all the available tags in your DRD network.

Global options

The following options are available for DRD's Drush commands

General options:
 --filter-cores            Filter the list by core id(s) they belong to                     
 --filter-drupal-versions  Filter the list by the drupal version of the core                
 --filter-ssl              Filter the list by the ssl-usage of the domain: yes=1|no=0       
 --filter-status           Filter the list by the status of the domain: active=1|disabled=0 
 --filter-tags             Filter the list by tags of the core

Additional domain options:
 --filter-domains          Filter the list by domain id(s) they belong to                   
 --filter-errors           Filter the list by the error status                              
 --filter-installed        Filter the list by the installation status                       
 --filter-warnings         Filter the list by the warnings status

Additional option for triggering an action:
 --ask                     Prompt the user to select the core and/or domain to work on

Options for action list:
 --mode                    Limit the actions to be listed by their mode: defaults to all but can be either any|server|domain

Options for tag list:
 --mode                    Limit the tags to be listed by their mode: defaults to all but can be either server or domain

DRD actions supported by core: use drush drd-list-actions to get a list of all actions provided by your system.

Main drush command drd-action

To trigger any of the actions that are also available from the DRD UI just use the drd-action drush command. Here are a couple of examples:

Check for project updates on all domains:
drush drd-action drd.list.updates

Check for project updates on all domains that run Drupal version 7.28:
drush drd-action drd.list.updates --filter-drupal-version=7.28

Enable maintenance mode on all domains:
drush drd-action drd.switch.maintenance --maintenancemode=1

Select an action from a list of all available actions, just don't provide any action to trigger:
drush drd-action

Getting more help

Global options are described above and some of DRD's actions come with additional options or parameters. To find out about these, there is a special usage for drd-action that takes help:[action-name] as its sole parameter. Example:

Get help on the action drd.switch.maintenance:
drush drd-action help:drd.switch.maintenance

Filtering cores and domains

With the filter options described above each of the actions can be limited to just some of the domains that are managed by DRD. If no filter is provided then each given action is triggered on all available domains.

Another way of limiting an action to just one or a few domains you can use the --ask option. This will provide you with a list of all cores or domains and you can select on which of those you want to trigger the action.

Tips & Tricks

Interested in a few powerful usage examples of DRD via Drush? We are providing some of them in the below list and extend that list over time if we come across other ones.

Get a list of available actions, select one and then select cores or domains on which to trigger that action:
drush drd-action --ask

Check for new domains on all enabled cores every night at 2am, configure crontab with the following line:
0 2 * * * drush @DRDALIAS drd-action drd.server.domains --filter-status=1 2>&1

Check for updates on all enabled domains every night at 3am, configure crontab with the following line:
0 3 * * * drush @DRDALIAS drd-action drd.list.updates --filter-status=1 2>&1

Have you found another one you would like to share with the community? Please leave a comment and we'll be happy to add yours to this list.

Comments

Dear mr. Haas,

We just discovered your DRD module and it looks great, thanks! We would like to perform Drush command using DRD, but we do not know how. Could you please help us on the way?

Thanks!
Koos

Sorry for the delay in blog posts, just too busy to get this done. But in short you have to have SSH2 enabled for PHP on the server that runs your DRD. On Ubuntu you can install that with

sudo apt-get install libssh2-php libssh2-1

and then restart apache. If that's available, then you can edit a core in your DRD and will find a new checkbox "Enable SSH2 support". If you turn that on you get a lot of extra settings that you need to fill in. Save your settings and then call the action "Update remote actions" and you will then get all additional Drush commands in your action list from then on.