Linux Format

A QUICK REFERENCE TO… SYSTEMD TIMERS

-

In its bid to take over the Linux universe, systemd has a special type of unit for timers, intended to replace the ageing, but still functionin­g cron. At first, creating a scheduled job using systemd seems more complicate­d as you need two unit files. The first is the .timer unit, which contains something like

[Timer] OnCalendar=03:30 Unit=foo.service

This would run the foo.service unit at 3:30am every day. The man pages show the full range of time specificat­ions available, and there are plenty of them. You can also set timers to run a number of seconds after certain events, such as booting. The above example gives a clue as to the second unit needed: it’s the service file to be called by the timer. Timers can’t run system commands directly. It’s normal, but not required, to give the timer and service files the same base name: foo.timer and foo.service.

This isn’t a straight replacemen­t for cron. Linking timers to systemd units means you can test the units separately from the timers because they run in exactly the same environmen­t, which is not the case when running commands or scripts from cron.

If you think you may as well use

systemd to handle this scheduling tasks because it’s running anyway, but can’t face the thought of converting all your

cron jobs, there’s an easy solution. You can run systemd-cron (https://github. com/systemd-cron/systemd-cron), which is a systemd service that converts your cron entries to systemd timers and creates new timers automatica­lly when you create new cron entries.

Newspapers in English

Newspapers from Australia