1 00:00:07,230 --> 00:00:10,410 - All right, let's talk about systemd timers. 2 00:00:10,410 --> 00:00:12,570 So a timer is what is used to start 3 00:00:12,570 --> 00:00:15,210 a corresponding service at a specific time 4 00:00:15,210 --> 00:00:18,288 or on occurrence of a specific event. 5 00:00:18,288 --> 00:00:21,510 The timer and service need to have the same filename 6 00:00:21,510 --> 00:00:23,761 just as we have seen for the sockets. 7 00:00:23,761 --> 00:00:27,750 And in in the timer you can use OnCalendar to specify 8 00:00:27,750 --> 00:00:31,143 when the timer should be started in a cron like style. 9 00:00:31,980 --> 00:00:35,370 And you can also use OnBootSec or OnUnitActiveSec 10 00:00:35,370 --> 00:00:38,287 to run a timer based on other events. 11 00:00:38,287 --> 00:00:40,710 When using timers the timer is 12 00:00:40,710 --> 00:00:43,170 enabled or started and not the service. 13 00:00:43,170 --> 00:00:45,750 And for more information have a look at the main page 14 00:00:45,750 --> 00:00:47,080 systemd.time 15 00:00:48,300 --> 00:00:51,480 Oh and in case you wonder how significant are these timers? 16 00:00:51,480 --> 00:00:54,720 Well, these timers are replacing good old cron jobs. 17 00:00:54,720 --> 00:00:56,580 On modern distributions and you will 18 00:00:56,580 --> 00:00:58,753 see that on CentOS for instance. 19 00:00:58,753 --> 00:01:01,500 Cron jobs are not the standard anymore. 20 00:01:01,500 --> 00:01:03,750 Systemd timers are the standard for anything 21 00:01:03,750 --> 00:01:05,730 that needs to be scheduled in the future. 22 00:01:05,730 --> 00:01:06,693 Let's check it out. 23 00:01:09,647 --> 00:01:10,480 (typing) 24 00:01:10,480 --> 00:01:15,230 So let me start using systemctl list unit files -t timer. 25 00:01:16,830 --> 00:01:19,320 I like this optional list unit files 26 00:01:19,320 --> 00:01:21,300 because list unit files is showing 27 00:01:21,300 --> 00:01:24,107 all the unit files not only the active units. 28 00:01:24,107 --> 00:01:27,180 As an alternative, you can use list units 29 00:01:27,180 --> 00:01:28,830 if you only want to get information 30 00:01:28,830 --> 00:01:31,709 about stuff that is currently running. 31 00:01:31,709 --> 00:01:34,500 Now here for instance, we have logrotate timer. 32 00:01:34,500 --> 00:01:36,240 That's something that previously was started 33 00:01:36,240 --> 00:01:41,100 by using a cron job and now it has become a systemd timer. 34 00:01:41,100 --> 00:01:45,417 So what this is doing well systemctl cat logrotate. 35 00:01:49,437 --> 00:01:54,120 The timer is showing the timer section OnCalendar is daily. 36 00:01:54,120 --> 00:01:57,930 AccuracySec is one hour and Persistent is true. 37 00:01:57,930 --> 00:02:01,365 Which means we wanna learn it every single day. 38 00:02:01,365 --> 00:02:03,480 More or less at the same time. 39 00:02:03,480 --> 00:02:05,250 AccuracySec is one hour. 40 00:02:05,250 --> 00:02:07,110 That means within a one hour difference 41 00:02:07,110 --> 00:02:09,600 of the previous time it was started. 42 00:02:09,600 --> 00:02:10,950 If you want to know what exactly the 43 00:02:10,950 --> 00:02:13,620 meaning is of all these options, use man. 44 00:02:13,620 --> 00:02:17,250 Man on systemd.timer which is showing 45 00:02:17,250 --> 00:02:20,610 what you can do inside the timer. 46 00:02:20,610 --> 00:02:23,580 But there's also man systemd.time 47 00:02:23,580 --> 00:02:26,850 which is more specifically about the time and date 48 00:02:26,850 --> 00:02:29,913 specification that you can use in your systemd timer. 49 00:02:31,380 --> 00:02:33,660 Good, let's check out another one. 50 00:02:33,660 --> 00:02:35,610 And that will be the fstrim. 51 00:02:35,610 --> 00:02:40,020 So systemctl cat on fstrim.timer 52 00:02:40,020 --> 00:02:44,700 is running fstrim on a weekly basis. 53 00:02:44,700 --> 00:02:46,289 Now, what is fstrim? 54 00:02:46,289 --> 00:02:51,210 Fstrim is about optimization of storage on SSD devices. 55 00:02:51,210 --> 00:02:54,537 So if you're on SSD it makes sense to run this. 56 00:02:54,537 --> 00:02:59,537 And you do that by using Systemctl enable - - fstrim.timer 57 00:03:03,840 --> 00:03:05,250 and that is going to make sure 58 00:03:05,250 --> 00:03:07,680 that the corresponding fstrim.service 59 00:03:07,680 --> 00:03:11,820 is going to be started on a weekly basis. 60 00:03:11,820 --> 00:03:14,910 And that's all there is to say about systemd timers. 61 00:03:14,910 --> 00:03:18,333 The replacement of cron in model Linux distributions.