1
00:00:06,530 --> 00:00:11,230
Let's talk about sysmd timers. That's the default
that you will find on Red Hat family Linux.

2
00:00:12,029 --> 00:00:17,920
So I'm going to use systemctl
t timer list units which will

3
00:00:17,920 --> 00:00:23,810
show all timer units that are
currently active. And here we can

4
00:00:23,810 --> 00:00:29,700
see a couple of these timer
units including for instance logrotate timer.

5
00:00:30,320 --> 00:00:35,325
So if I'm going to
check what is going on, next

6
00:00:35,325 --> 00:00:40,329
thing that you need to
know is systemctl list units logrotate.

7
00:00:42,350 --> 00:00:48,129
How does it work? Well, we have logrotate
timer and logrotate timer is going to trigger

8
00:00:48,129 --> 00:00:53,909
something else. But hey, what is something else?
Well, I don't see it as a unit.

9
00:00:54,729 --> 00:00:59,170
Let's have a look at
systemctl list unit unit fails

10
00:00:59,170 --> 00:01:03,609
and there we can see
that suddenly logrotate service appears.

11
00:01:04,409 --> 00:01:05,510
So what
is the relation?

12
00:01:06,349 --> 00:01:11,687
The timer triggers the service. They need
to have the same first name. You

13
00:01:11,687 --> 00:01:17,025
do not activate the service, you activate
the timer and that's what you are

14
00:01:17,025 --> 00:01:22,362
going to see. If I would use
systemctl status on logrotate service then you

15
00:01:22,362 --> 00:01:27,700
can see it has active
inactive, but it has triggered by.

16
00:01:28,079 --> 00:01:31,939
Hey, this guy will
be triggered by logrotate timer.

17
00:01:32,439 --> 00:01:39,383
And then if we check what the timer
is doing itself. Well, systemctl cat on logrotate timer

18
00:01:39,383 --> 00:01:46,326
is showing that the timer is activating daily
and it's persistent. So it will remember what it

19
00:01:46,326 --> 00:01:53,269
has done and randomized delay. Second it will
run more or less within the same hour.

20
00:01:53,829 --> 00:01:57,890
And that is what is making sure
that logrotate is running on a daily basis.

21
00:01:58,900 --> 00:02:04,053
Now let's have a
look at systemctl list

22
00:02:04,053 --> 00:02:09,206
unit files this time
minus the timer there

23
00:02:09,206 --> 00:02:14,360
we can see that
different timers are available.

24
00:02:15,939 --> 00:02:19,500
Is there something that
I want to activate?

25
00:02:20,280 --> 00:02:24,719
Well, I was thinking fstream timer
but fstream timer is already activated.

26
00:02:25,550 --> 00:02:27,310
That is
so disappointing.

27
00:02:28,189 --> 00:02:32,849
So I need something that
makes sense in a different way.

28
00:02:33,689 --> 00:02:39,110
But be careful, you can't just activate
anything without knowing what is going on.

29
00:02:40,169 --> 00:02:43,439
So yeah, maybe I'm not
going to do it at all.

30
00:02:44,340 --> 00:02:47,560
Or maybe I'm going
to create my own timer.

31
00:02:48,219 --> 00:02:52,310
You know what I'm going to do? Let's
do something advanced, something a little bit fun.

32
00:02:53,319 --> 00:02:59,126
I'm going to
the ETC systemd

33
00:02:59,126 --> 00:03:04,933
system directory and
I'm going to

34
00:03:04,933 --> 00:03:10,740
copy from user
lib systemd system.

35
00:03:11,819 --> 00:03:17,935
I'm going to
copy HTTPD service to

36
00:03:17,935 --> 00:03:24,050
here and I'm
calling it Sander service.

37
00:03:24,569 --> 00:03:28,819
Now what am I doing? Well, I'm
going to build it up from scratch. I'm

38
00:03:28,819 --> 00:03:33,069
creating my service and I want the
service to be started by a timer.

39
00:03:33,669 --> 00:03:37,724
Now I don't like finding
out everything from scratch and that's

40
00:03:37,724 --> 00:03:41,780
why I'm using this HTTP
service as an example file.

41
00:03:42,439 --> 00:03:47,449
And likewise I'm
going to copy fstream

42
00:03:47,449 --> 00:03:52,459
timer to colon
slash Sander timer.

43
00:03:53,620 --> 00:03:57,634
That's because if you want to
run it through a timer then it's

44
00:03:57,634 --> 00:04:01,649
on a first name basis and
the first name basis here is sander.

45
00:04:02,189 --> 00:04:08,615
So I am going to use sudo vim
on Sander service to change my service. Well,

46
00:04:08,615 --> 00:04:15,040
there's a lot that I can remove
and I'm going to do all of that.

47
00:04:18,040 --> 00:04:21,769
The only thing really that I
need, I need a type for

48
00:04:21,769 --> 00:04:25,500
my service and the type is
going to be set to simple.

49
00:04:26,259 --> 00:04:27,439
I need
an exec start.

50
00:04:29,800 --> 00:04:31,980
Everything else
can go.

51
00:04:32,680 --> 00:04:37,843
What is the exec start? Well, the
exec start is going to be a

52
00:04:37,843 --> 00:04:43,006
dummy command like user bin sleep infinity
which no, not sleep infinity sleep 60.

53
00:04:43,006 --> 00:04:48,170
So we are going to sleep
60 seconds every now and then.

54
00:04:49,110 --> 00:04:53,659
So now I have my service,
I'm going to create my timer.

55
00:04:53,659 --> 00:04:58,209
So sudo vim standard timer and
there I have my unit description.

56
00:04:59,110 --> 00:05:02,709
I like it to be
descriptive. So sonder timer and.

57
00:05:03,490 --> 00:05:07,615
And the other stuff I don't need.
And I have my timer section, I

58
00:05:07,615 --> 00:05:11,740
can keep my timer section which is
going to run the service every week.

59
00:05:12,259 --> 00:05:18,694
And the only thing that I need to do
right now, well first systemctl daemon reload because I

60
00:05:18,694 --> 00:05:25,129
configured a lot of files on disk not
using systemd so I do need my system daemon.

61
00:05:26,430 --> 00:05:28,910
So I do need
my systemctl daemon reload.

62
00:05:29,529 --> 00:05:36,257
Now I need sudo systemctl enable
timer and that is going to enable

63
00:05:36,257 --> 00:05:42,985
the timer enable makes it will
start well booting well, I also need

64
00:05:42,985 --> 00:05:49,712
to start it now. So let's
do a start and let's check out

65
00:05:49,712 --> 00:05:56,439
using systemctl status on standard
service what is going on?

66
00:05:56,959 --> 00:06:02,036
And there you can see it's inactive but
it will be triggered by the sonder timer. So

67
00:06:02,036 --> 00:06:07,113
what? Have you just seen how easy it
is to create your own systemd service files to

68
00:06:07,113 --> 00:06:12,189
run any command and how easy it
is to schedule them using a systemd timer?
