External Drupal Cron
Reviewed 230525
Drupal has a cronjob that is run periodically to run any background tasks within the content management system. This page covers some of the configuration around it.
Pantheon Cron
Pantheon's Cron is run once an hour, generally between 5-10 minutes past the hour. They don't have a mechanism to increase the amount of times the cron is run. However, we do have some options available to us...
New Relic Synthetic Monitoring
Pantheon's New Relic can run Drupal's Cron.
Configure an external URL to run cron at admin/config/system/cron .
Visit Pantheon's New Relic by clicking on the "New Relic" button in the Pantheon's Site's Dashboard
Go to "Synthetic monitoring tab on the right-hand menu
Click "Create your first monitor"
Click "Create a new Ping monitor"
Use the name "Drupal Cron", with the tag "cron"
Set the URL to be Drupal's cron URL at admin/config/system/cron
Click "Save"
Now you will be able to monitor when the cron is run directly through New Relic.
Triggering Cron from a remote server
First, make sure that drush is installed on the server in question (duh).
For drush to successfully execute via cron, we must explicitly specify the PATH for environment variables. This will vary per server. (echo $PATH).
We must also set columns to bypass errors we'd occasionally get since we are not running drush via the terminal.
We use the absolute path for drush; cron doesn't know any better.
We pass the quiet flag, so that success, progress, and email messages are suppressed.
10 * * * * /usr/bin/env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin COLUMNS=72 /usr/local/bin/drush --root=/var/www/mysite.com/public_html --uri=http://mysite.com --quiet cron
If you're running cron locally, you set it to run as the user with webserver permission, typically www-data:
$ sudo -u www-data crontab -e
Using drush aliases
It's much cleaner and maintainable to manage drush aliases, though.
2 3 10,20,30 * * /usr/local/bin/drush @mysite.live --quiet cron
the aliases.drushrc.php file will need to reside in the home directory of the user running cron.
Triggering cron via HTTP
We can trigger cron by visiting a URL. Drupal 7 introduces a secure token to this approach to protect the server from DDoS attacks.
You can run cron at the URL secured by visiting the site's unique token in the browser, like so:
https://mysite.com/cron.php?cron_key=y85HnNQxjdqM-deRXj2Xrp2MJumqe1HGPSXhW8jftyI
Drupal 6
Running cron as user1
Here is how we would set up cron job with curl, and authenticate as user1. No token required.
HttpAuth
In drupal 6, we can still use drush, but here is another way to do the same thing with wget AND bypass HttpAuth password block, such as can be provided by .htaccess, httpd.conf or by nginx.
note that if someone has access to running processes, username/password will be visible on the server running cron
Running cron over SSL
When using SSL, add one additional argument when calling wget: --no-check-certificate. Do not put “--no-check-certificate” between the -0 and the -.
Resources
run drupal cron tasks from Drush: http://drush.ws/docs/cron.html
Configuring cron jobs using the cron command: https://drupal.org/node/23714
Review History
Who | When | Status |
---|---|---|
Bob | 20230525 | Current |