Disable Drupal's Automatic Cron

Drupal 7 was released with an automatic cron option which is handy for those who do not have shell access or a way to enable a Unix type cron with their web host.

At Classic, we use Jenkins to trigger cron via Drupal's cron URL. Because we have cron scheduled, we have no need for Drupal's built-in automatic cron which defaults to run every 3 hours. Also, we sometimes have to disable the Jenkins cron during deployments to make sure that that cron doesn't execute until all code has been deployed successfully.

There are a number of ways to disable Drupal 7's automatic cron if you decide you do not need it. I have outlined these options below. You can decide which is the best for your situation.

Drupal UI

The Drupal UI is always a great way to go for confirmation settings.

Go to the following path admin/config/system/cronand set the "Run cron every" drop-down to "Never". Next, click the "Save Configuration" button.

Drupal%207%20cron%20configraution%20screen

Drush

Many prefer to use Drush and find it faster and easier than using the Drupal UI for configuration tasks.

Run the following Drush command in your terminal. Make sure to change directory to your Drupal install. drush vset cron_safe_threshold 0

settings.php

Setting configuration variables in the settings.php is a great way to lock in changes that you don't want someone to change in the Drupal UI.

Add the following to your settings.php: $conf['cron_safe_threshold'] = 0;

hook_update_N function

I often find adding configuration changes to hook_update_N functions a great way to make configuration changes during deployments.

Simply add the following line of code inside your hook_update_N function: variable_set('cron_safe_threshold', 0);

Drupal 8

Drupal 8's automatic cron setting currently defaults to "Never". According to this issue, the intent is to still have Drupal's automatic cron default to run every 3 hours.

It looks like disabling Drupal 8's automatic cron can be done in the Drupal UI or through the configuration override system. I need to dig deeper to test which options will work best for our environment as we move to Drupal 8.

Blog Category: