Triggering regular tasks with Systemd

Alarm Clock

Author(s):

Systemd can start timers that automatically perform tasks at specified times. The configuration files are known as timer units.

You might want to use your Linux system to automatically create a backup every evening and rotate the log files at regular intervals. In most distributions, time-controlled tasks are handled by the Cron daemon. But Systemd is an interesting alternative to Cron. Systemd controls the startup process of most distributions, and it can also trigger time-controlled and recurring tasks.

Service Providers

The first task is to tell Systemd which task to perform. To do this, you create a configuration file, the Service Unit. Listing 1 shows an example.

A service unit is a text file divided into several sections. The [Service] section is required. ExecStart= is followed by the command to be executed by the system. In Listing 1, Systemd would simply run a script that backs up the system to the /mnt directory. The [Unit] section adds some metadata. In the simplest case, Description= is followed by a description of the task.

[...]