1
00:00:00,000 --> 00:00:13,240
Let's talk about systemd-timers. A systemd-timer is an alternative for a cronjob. And cronjobs

2
00:00:13,240 --> 00:00:20,440
in the past have always been used to start some tasks at a specific moment. Currently,

3
00:00:20,440 --> 00:00:26,639
timers and cronjobs are used side by side, but systemd-timers are slowly replacing cronjobs.

4
00:00:26,639 --> 00:00:31,520
For Red Hat Linux, for instance, you will notice that there is no more default cronjobs.

5
00:00:31,520 --> 00:00:37,759
It's all done by timers if it needs to be done periodically. You can use systemctl listunits

6
00:00:37,759 --> 00:00:43,959
minus t-timer for a list of timers that are currently active. Timers have a matching service

7
00:00:43,959 --> 00:00:50,180
file, and the service file typically has the same name. That is how the timer finds the

8
00:00:50,180 --> 00:00:56,720
matching file. For instance, fstrim.timer works with fstrim.service. And to use timers,

9
00:00:56,720 --> 00:01:00,939
you enable the timer. You don't enable the service. Because you don't want the service

10
00:01:00,939 --> 00:01:05,459
to be running at all time, you want the timer to be running and to trigger the service when

11
00:01:05,459 --> 00:01:13,459
the time is there. So systemctl enable fstrim.timer is what you would be doing. You can consult

12
00:01:13,459 --> 00:01:20,860
man systemd.timer for more details about the timer unit type, and also systemd.time

13
00:01:20,860 --> 00:01:31,180
for more details about the time settings that you can use. Let me show you. So systemctl

14
00:01:31,180 --> 00:01:38,300
listunit files minus t-timer. I'm doing listunit files here, because listunit files normally

15
00:01:38,300 --> 00:01:45,580
gives a little bit more information. And what do we see? Do we have anything interesting?

16
00:01:45,580 --> 00:01:52,339
Well, we can see fstrim.timer. We can analyze what is going on in fstrim.timer. So let's

17
00:01:52,339 --> 00:02:01,860
use systemctl status fstrim.timer, where we can see the unit file that it has loaded.

18
00:02:01,860 --> 00:02:07,220
It's enabled. The preset is enabled, so it was enabled by default. And it's active and

19
00:02:07,220 --> 00:02:13,860
currently waiting. Then we can see a trigger, three days left. And the trigger, so it will

20
00:02:13,860 --> 00:02:23,020
trigger fstrim.service. So systemctl status on fstrim.service is giving me what? It's

21
00:02:23,020 --> 00:02:29,020
only giving me active, inactive, and triggered by fstrim.timer. And the green dot is indicating

22
00:02:29,020 --> 00:02:37,899
that fstrim.timer is indeed listening. So if we check the contents of the timer, fstrim.timer

23
00:02:37,899 --> 00:02:43,860
in systemctl cat, then we see the timer section. And in the timer section, you define how you

24
00:02:43,860 --> 00:02:50,300
want it to be started. So on calendar is weekly. You should do this on a weekly basis. Accuracy

25
00:02:50,300 --> 00:02:55,779
sec is one hour, which means more or less within an hour time frame of the last time

26
00:02:55,779 --> 00:03:02,100
it started. Persistent is true, which means we keep the information about the timer activity

27
00:03:02,100 --> 00:03:10,419
across reboots. And randomized delay seconds, every time we give a 100 minutes randomization.

28
00:03:10,419 --> 00:03:15,539
If you want to know more about the way so you can run a timer, I can really recommend

29
00:03:15,539 --> 00:03:22,619
to have a look at mansystemd.time. Timer is for the unit. Time is for the way how you

30
00:03:22,619 --> 00:03:30,860
can define it. And you get information about timestamps and even about calendar events

31
00:03:30,860 --> 00:03:37,139
right here. So it's very precise in when exactly you want to run it. And if we have a look

32
00:03:37,139 --> 00:03:43,539
at systemd.timer, well, you get some more information about the options. I like table

33
00:03:43,539 --> 00:03:49,820
one here. In table one, we see some interesting options that allow you to run the timer really

34
00:03:49,820 --> 00:03:57,259
in a conditional way. So on active sec means that you are going to run it specific moment

35
00:03:57,259 --> 00:04:03,220
after the timer has been activated. On boot sec means that you are going to run it after

36
00:04:03,220 --> 00:04:08,020
booting. On unit active sec, that's a very nice one that is going to monitor another

37
00:04:08,020 --> 00:04:15,580
unit and is going to run a couple of seconds, minutes, hours, or whatever after that unit

38
00:04:15,580 --> 00:04:23,540
has been activated. So lots of options with your systemd.timer. You can still run crontabs

39
00:04:23,540 --> 00:04:32,059
if you want to. I mean, I can still run crontab minus e student. Sorry, crontab minus e for

40
00:04:32,059 --> 00:04:43,899
the editor minus u student and put something like slash, star slash 10 for every 10 minutes.

41
00:04:43,899 --> 00:04:50,779
If you want to get longer greetings from students, that will still work, but timer has become the

42
00:04:50,779 --> 00:04:56,660
default. So on rel 10, you don't find any crontabs anymore. That will show if you use

43
00:04:56,660 --> 00:05:05,179
ls on etc crontab star dot star. As you can see, it's nearly empty. Timers are the standard nowadays.

