• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Urban Penguin

The Urban Penguin - Linux Training

  • Home
  • About
  • Programming
    • Master Editing Text Files Using VIM
    • Learn Shell Scripting with BASH
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell
    • Learn C Programming using Linux and the Raspberry Pi
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
  • OS Tutorials
    • Red Hat and CentOS Training
      • Red Hat Enterprise Linux System Administration 1 – RH124
      • RHCSA – System Admin 2 – RH134
      • RHCE – EX294 – Automation With Ansible
    • Learning Ubuntu
    • LPI Training
      • LPI Linux Essentials
      • LPIC-1 Linux Administrator
      • LPIC-2 Certified Linux Engineer
      • LPIC-3 Senior Level Certification
        • LPIC-3 Exam 300 : Mixed Environments
        • LPIC-3 Exam 303 : Security
        • LPIC-3 Exam 304 : Virtualization and High Availability
    • Linux Technologies
      • Apache HTTPD Server
      • Learning PHP
      • Learning PUPPET
      • Learning SAMBA
      • Linux File-Systems
      • Monitoring with Nagios Core
      • MYSQL
      • openLDAP Directories on Linux
You are here: Home / Linux / RH134 / RHCSA 8 – Systemd Timer Units

RHCSA 8 – Systemd Timer Units

December 14, 2019 by The Urban Penguin

RHCSA 8 Study Guide

A new method of scheduling tasks that is part of the systemd eco-system are systemd timer units. These activate service units on specific intervals. The documentation for these timer units can be read using the man pages:

# man 5 systemd.timer

We can list currently installer timer units, we should know that we can use systemctl for this:

# systemctl list-unit-files --type=timer

 

We would expect to have the dnf/yum makecache timer. This ensures that the metadata for the repositories is kept up-to-date. It will run 10 minutes after boot and then hourly after this. An easy way to quickly check the age of the metadata is to run a check-update with yum. This does not do anything other than list available updates but does show the metadata age:

# yum check-update | head -n1
Last metadata expiration check: 0:02:15 ago on Wed 27 Nov 2019 14:36:51 GMT.

Here we can see the metadata was updated 2 minutes before the command was run. So, how does this work. The easiest way is to dice straight into the timer unit. Using systemctl cat we can list the contents of the unit file:

# systemctl cat dnf-makecache.timer
# /usr/lib/systemd/system/dnf-makecache.timer
[Unit]
Description=dnf makecache --timer
ConditionKernelCommandLine=!rd.live.image
# See comment in dnf-makecache.service
ConditionPathExists=!/run/ostree-booted
Wants=network-online.target
[Timer]
OnBootSec=10min
OnUnitInactiveSec=1h
Unit=dnf-makecache.service
[Install]
WantedBy=multi-user.target

The timer OnBootSec=10min runs the unit file 10 minutes after booting. The OnUnitInactive=1h means that it will run again 1 hour after the unit file becomes inactive. If the unit file runs at 10:00 and takes 2 minutes to run; it will run again at 11:02. The execution of the actual command is handled by the Unit=dnf-makecache.service entry. This unit file is disabled but runs when called by the timer unit. We can check when it last run through the status:

# systemctl status dnf-makecache.service  | grep Active
   Active: inactive (dead) since Wed 2019-11-27 14:36:51 GMT; 11min ago

The timer should execute again on my system at 15:36. However a more simple way of checking when a timer last ran and will run again is provided with the sub-command list-timers:

$ systemctl list-timers 
NEXT                         LEFT       LAST                         PASSED    UNIT                  >
Thu 2019-12-12 16:32:14 UTC  20min left Wed 2019-12-11 16:32:14 UTC  23h ago   systemd-tmpfiles-clean>
Thu 2019-12-12 16:41:22 UTC  29min left Thu 2019-12-12 15:41:22 UTC  30min ago dnf-makecache.timer   >
Fri 2019-12-13 00:00:00 UTC  7h left    Thu 2019-12-12 00:00:01 UTC  16h ago   unbound-anchor.timer

Installing new package that make use of systemd timers will add to the list of enabled timers. For example, the sysstat package used to make use of crond to schedule its tasks now it uses systemd timer units.

# yum install sysstat
# systemctl cat sysstat-collect.timer
[Unit]
Description=Run system activity accounting tool every 10 minutes
[Timer]
OnCalendar=*:00/10
[Install]
WantedBy=sysstat.service

The OnCalendar timer will run every hour starting on the hour and then every 10 minutes and is used to gather system performance data. Expect to see more on these systemd timer units as they are here to stay.

Online Instructor Led Classes from TheUrbanPenguin

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Tumblr (Opens in new window)
  • Click to print (Opens in new window)

Filed Under: RH134

Primary Sidebar

Newest Video

The Urban Penguin On Youtube

Categories

Pages

  • About The Urban Penguin
  • Contact Us
  • Linux Technologies
    • Apache HTTPD Server
    • Learning PHP
    • Learning PUPPET
    • Learning SAMBA
    • Linux File-Systems
    • Monitoring with Nagios Core
    • MYSQL
    • openLDAP Directories on Linux
  • LPI Training from The Urban Penguin
    • Complete Linux Essentials
    • Live and Pluralsight hosted courses
    • LPI Linux Essentials
    • LPI Linux Essentials for Raspberry Pi
    • LPIC-1 Linux Administrator
    • LPIC-2 Certified Linux Engineer
    • LPIC-3 Senior Level Certification
      • LPIC-3 Exam 300 : Mixed Environments
      • LPIC-3 Exam 303 : Security
      • LPIC-3 Exam 304 : Virtualization and High Availability
  • Online Instructor-led Courses
    • Bash Scripting Masterclass
    • Nftables Masterclass
    • Red Hat Enterprise Linux System Administration 1 – RH124
    • SELinux Masterclass
  • OpenStack
    • Citrix Videos
    • Pluralsight
    • Raspberry Pi Tutorials
    • Udemy
  • Operating System Tutorials
    • Learning SUSE
    • Learning Ubuntu
    • Linux Foundation Training
    • Red Hat and CentOS Training
      • RHCE – EX294 – Automation With Ansible
      • RHCSA – System Admin 1 – RH124
      • RHCSA – System Admin 2 – RH134
    • Solaris 11 OCA 1ZO-821
  • Scripting – the power of repetition!
    • General Java Tutorials
    • Java 7 OCA Exam 1ZO-803
    • Learn C Programming using Linux and the Raspberry Pi
    • Learn Shell Scripting with BASH
    • Master Editing Text Files Using VIM
    • PERL Scripting in Linux
    • Ruby Scripting in Linux
    • Scripting with PowerShell

© 2022 The Urban Penguin · All Rights Reserved