Skip to content

ragnarkurmwunder/cron-drush

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

Cron Drush

This script is intended to run Drupal activities from system cron by help of Drush.

Originally it has been developed in AWS context, so it may contain some specifics.

Installation

  1. Copy the script to your system /usr/local/bin/cron-drush.sh
  2. Give it execution rights chmod 755 /usr/local/bin/cron-drush.sh
  3. Configure system cron (see below)
  4. Configure environment variables (see below)

System Cron

  1. Create new cron file (for example /etc/cron.d/drush)
  2. Add an entry (see example below)
  3. Configure environment variables

Example

WEBUSER=apache2
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
0 * * * *  root  cron-drush.sh cron

Environment variables

Those variables have to be specified in cron file, or in AWS case those can be also in envvars which is used automatically.

All environment variables are optional.

  • BASE_URL

    In makes sense only in single-site setup when some Drupal functionality may need it and creating drush aliases files is not needed.
    Example: https://www.example.com

  • COMPOSER_HOME

    This is needed for script to find drush. In composer dir there is vendor/bin which contains drush.
    Default: /usr/lib/composer/vendor/bin/drush

  • CRON_DRUSH_LOG

    Location cron drush logfile.
    Default: /var/log/cron-drush.log

  • LEADER_SCRIPT

    This is needed only in multi-instance setup where there are multiple web servers against one database. The script determines by exit code 0 which instance is considered "leader" in the group.
    The value may be absolute path or relative path. In latter case the script is searched from PATH.
    Default: aws-leader.py, if present in the system.

  • WEBROOT

    Drush needs to know where Drupal is located.
    Default: tries to guess between some common paths.

  • WEBUSER

    Specifies web server user for running drush as.
    Default: tries to guess between some common usernames.

Usage

  • This script is meant to be executed from system cron
  • This script is meant to be executed as root
  • It passes it's arguments to drush, so accepts arbitrary drush arguments, not just cron
  • See logs at /var/log/cron-drush.log
  • Create leader script if needed.

Running multi-site

Modify your cron file. For example:

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
0 * * * *  root  cron-drush.sh @site1 cron ; cron-drush.sh @site2 cron

Drop drush aliases file into /etc/drush folder, so that homeless webserver user can find it.

References:

About

Execute drush properly from cron

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages