- All right, let's talk about systemd timers.
So a timer is what is used to start
a corresponding service at a specific time
or on occurrence of a specific event.
The timer and service need to have the same filename
just as we have seen for the sockets.
And in in the timer you can use OnCalendar to specify
when the timer should be started in a cron like style.
And you can also use OnBootSec or OnUnitActiveSec
to run a timer based on other events.
When using timers the timer is
enabled or started and not the service.
And for more information have a look at the main page
systemd.time
Oh and in case you wonder how significant are these timers?
Well, these timers are replacing good old cron jobs.
On modern distributions and you will
see that on CentOS for instance.
Cron jobs are not the standard anymore.
Systemd timers are the standard for anything
that needs to be scheduled in the future.
Let's check it out.
(typing)
So let me start using systemctl list unit files -t timer.
I like this optional list unit files
because list unit files is showing
all the unit files not only the active units.
As an alternative, you can use list units
if you only want to get information
about stuff that is currently running.
Now here for instance, we have logrotate timer.
That's something that previously was started
by using a cron job and now it has become a systemd timer.
So what this is doing well systemctl cat logrotate.
The timer is showing the timer section OnCalendar is daily.
AccuracySec is one hour and Persistent is true.
Which means we wanna learn it every single day.
More or less at the same time.
AccuracySec is one hour.
That means within a one hour difference
of the previous time it was started.
If you want to know what exactly the
meaning is of all these options, use man.
Man on systemd.timer which is showing
what you can do inside the timer.
But there's also man systemd.time
which is more specifically about the time and date
specification that you can use in your systemd timer.
Good, let's check out another one.
And that will be the fstrim.
So systemctl cat on fstrim.timer
is running fstrim on a weekly basis.
Now, what is fstrim?
Fstrim is about optimization of storage on SSD devices.
So if you're on SSD it makes sense to run this.
And you do that by using Systemctl enable - - fstrim.timer
and that is going to make sure
that the corresponding fstrim.service
is going to be started on a weekly basis.
And that's all there is to say about systemd timers.
The replacement of cron in model Linux distributions.