Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

9.7. Automatically Refreshing Package Database and Downloading Updates with Yum-cron

The yum-cron service checks and downloads package updates automatically. The cron jobs provided by the yum-cron service are active immediately after installation of the yum-cron package. The yum-cron service can also automatically install downloaded updates.
With default settings, the yum-cron service:
The yum-cron service has two configuration files:
For daily tasks.
For hourly tasks.

9.7.1. Enabling Automatic Installation of Updates

To enable automatic installation of downloaded updates, edit the daily configuration file for daily installation or the hourly configuration file for hourly installation by setting the apply_updates option as follows:
apply_updates = yes

9.7.2. Setting up Optional Email Notifications

By default, the yum-cron service uses cron to send emails containing an output of the executed command. This email is sent according to cron configuration, typically to the local superuser and stored in the /var/spool/mail/root file.
You can use specific email configuration different from the settings which affect all cron jobs. However, this email configuration does not support TLS and overall email built-in logic is very basic.
To enable yum-cron built-in email notifications:
  1. Open selected yum-cron configuration file:
    For daily tasks.
    For hourly tasks.
  2. In the [emitters] section, set the following option:
    emit_via = email
  3. Set the email_from, email_to, email_host options as required

9.7.3. Enabling or Disabling Specific Repositories

The yum-cron does not support specific configuration of repositories. As a workaround for enabling or disabling specific repositories for yum-cron but not for yum in general follow the steps bellow:
  1. Create an empty repository configuration directory anywhere on the system.
  2. Copy all configuration files from the /etc/yum.repos.d/ directory to this newly created directory.
  3. In the respective .repo configuration file within the /etc/yum.repos.d/, set the enabled option as follows:
    enabled = 1
    To enable the repository.
    enabled = 0
    To disable the repository.
  4. Add the following option, which points to the newly created repository directory, at the end of the selected yum-cron configuration file:

9.7.4. Testing Yum-cron Settings

To test yum-cron settings without waiting for the next scheduled yum-cron task:
  1. Open selected yum-cron configuration file:
    For daily tasks.
    For hourly tasks.
  2. Set the random_sleep option in the selected configuration file as follows:
    random_sleep = 0
  3. Run the configuration files:
    # yum-cron /etc/yum/yum-cron.conf
    # yum-cron /etc/yum/yum-cron-hourly.conf

9.7.5. Disabling Yum-cron messages

The yum-cron messages cannot be entirely disabled, but can be limited to messages with critical priority only. To limit the messages:
  1. Open selected yum-cron configuration file:
    For daily tasks.
    For hourly tasks.
  2. Set the following option in the [base] section of the configuration file:
    debuglevel = -4

9.7.6. Automatically Cleaning Packages

The yum-cron service does not support any configuration option for removing packages similar to the yum clean all command. To clean packages automatically, you can create a cron job as an executable shell script:
  1. Create a shell script in the /etc/cron.daily/ directory containing:
    yum clean all
  2. Make the script executable:
    # chmod +x /etc/cron.daily/