8

I have a staging and dev setup, but I wonder if I can disable cron on these as I don't want cron firing. It's mainly because I have backup migrate module scheduled to backup my site everyday, but I don't want this executing every time.

0

4 Answers 4

17

Yes, you can do this in your settings.php file (as you have mentioned that is the only difference between versions).

You would do it like this (in your settings.php file):

Drupal 7:

// Disable drupal's built in cron trigger.
$conf['cron_safe_threshold'] = 0;

Drupal 8/9:

// Disable drupal's built in cron trigger.
$config['automated_cron.settings']['interval'] = 0;

For more information see Defining variables in a site's settings.php $conf array.

Edit How this works is:

  1. Variables are loaded from the database (or the cache if they have already been cached).
  2. If those variables were not already in the cache they are saved to the cache.
  3. The $conf variables from the settings file are added to the variables and take precedence over variables from the database.

So variables from the database are cached, but variables from settings.php are not.

3
  • does this take immediate effect once i add this variable to my settings.php file? or do i have to do a refresh somewhere? May 25, 2013 at 17:38
  • You should not have to do anything to pick up the change. - A have added a note to my answer about how the variables are loaded.
    – rooby
    May 26, 2013 at 9:38
  • 2
    For Drupal 8, see this answer
    – No Sssweat
    Oct 2, 2018 at 7:54
5

Go to /admin/config/system/cron and set it to 'Never'. If you have an external crontab task, disable it.

2
  • would i be able to set this in the settings.php as the only differences i have on each environment is only in that file. May 25, 2013 at 1:04
  • 1
    No. Just do it in the admin interface and remember to turn it back on in the production environment. Actually you should turn it back on in the local server before you migrate, just to make sure everything is working.
    – Triskelion
    May 25, 2013 at 1:06
5

As others have said there are modules out there to switch environments between different servers. For example a development server vs testing server vs production server.

A few are: Environment and Drush Environment.

Environment for example lets you write your own hook to easily manage what happens when you switch to a new environment. From the module page:

/**
 * Implementation of hook_environment_switch().
 */
function YOUR_MODULE_environment_switch($target_env, $current_env) {
  // Declare each optional development-related module
  $devel_modules = array(
    'bulk_export',
    'context_ui',
    'devel',
    'devel_generate',
    'devel_node_access',
    'imagecache_ui',
    'update',
    'spaces_ui',
    'views_ui',
  );

  switch ($target_env) {
    case 'production':
      module_disable($devel_modules);
      drupal_set_message('Disabled development modules');
      return;
    case 'development':
      module_enable($devel_modules);
      drupal_set_message('Enabled development modules');
      return;
  }
}
?>

You could with little trouble write a line of PHP that turns off Cron if your in the Testing environment server. I'm using Environment's hook on 1 project to perform the following tasks on a non-production server:

  module_enable($devel_modules); // A list of modules to enable.
  drupal_flush_all_caches();
  drupal_set_message('Enabled development/staging modules');

  // Configure Enviroment Indicator Module
  variable_set('environment_indicator_color',"#d00c0c");
  variable_seT('environment_indicator_margin', 1);
  variable_set('environment_indicator_position', "right");
  variable_set('environment_indicator_text',"MY STAGING SERVER");
  variable_set('environment_indicator_enabled','1');
  drupal_set_message(t('Configured environment indicator.'));
0

If your concern is just Backup and Migrate, you can export Backup and Migrate settings to settings.php (2.x branch) or export Backup and Migrate settings using the Features module (3.x branch).

I do this myself because I want to keep things as close to production as possible but can't have Backup and Migrate running all the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.