Systemd Timers

Intro

systemd’s Timers are units. Units are the simplest form of systemd files. Units are describing “when and if” a unit service “should or must” run, based on real or relative time.

A real time example is similar to a cron job entry. You can find out all the configuration settings/values for OnCalendarhere.

A relative time example is more close to something like:
“Run this unit service, ten minutes after boot, before this service and also that services must have already been started cause I am depend on them.”

List of systemd-timers

To view the declared timers on a systemd, run the below command:

$ systemctl list-timers

we can see all timers, even the in-active ones, with:

# systemctl list-timers --all

one simple example

ok, let’s start with an example.

I’ll use the /usr/local/bin directory to store my custom scripts, as this directory is in the PATH enviroment variable and I can run these scripts from anywhere.

Our systemd unit files, must be under the /etc/systemd/system/ directory.

Part One: The Script

As an example, the script will mount some volumes after boot time.
The basic script contents the below lines:

# cat /usr/local/bin/mount.volumes.sh

#!/bin/sh
/usr/bin/mount /mnt/backup
/usr/bin/mount /var/lib/docker

and make it executable:

# chmod +x /usr/local/bin/mount.volumes.sh

You can run this script, once or twice to see if everything goes as planned.