1 00:00:00,000 --> 00:00:10,320 Let's talk about dependencies in systemd. 2 00:00:10,320 --> 00:00:12,760 So you can manage unit dependencies. 3 00:00:12,760 --> 00:00:18,680 And these dependencies normally are defined in the unit section within the unit file. 4 00:00:18,680 --> 00:00:24,680 An easy way to figure out about the current dependencies is systemctl list dependencies. 5 00:00:24,680 --> 00:00:29,280 That is something that you can do without an argument to see all the dependencies that 6 00:00:29,280 --> 00:00:35,799 have brought you into the current state, or use an argument such as systemctl list dependencies 7 00:00:35,799 --> 00:00:43,360 boot.mount to show the current dependencies that are required by a specific unit. 8 00:00:43,360 --> 00:00:47,759 You can also use options within the unit file to manage dependencies. 9 00:00:47,759 --> 00:00:52,320 Use requires, which means that if this unit loads, the units that are listed here will 10 00:00:52,320 --> 00:00:53,599 load as well. 11 00:00:53,599 --> 00:00:58,919 And if one of the other units is deactivated, this unit will be deactivated as well. 12 00:00:58,919 --> 00:00:59,919 There is a requisite. 13 00:00:59,919 --> 00:01:04,720 A requisite is what you use if you must have the unit already available, otherwise this 14 00:01:04,720 --> 00:01:06,599 unit will fail. 15 00:01:06,599 --> 00:01:09,320 There is once, which is a soft dependency. 16 00:01:09,320 --> 00:01:13,440 It means that this unit wants to load the units listed here, but it won't fail if any 17 00:01:13,440 --> 00:01:15,480 of these units fail. 18 00:01:15,480 --> 00:01:20,800 And we have before, which will start this unit before the unit mentioned with before. 19 00:01:20,800 --> 00:01:26,800 And after, we'll start this unit after the unit that is mentioned with after equals. 20 00:01:26,800 --> 00:01:29,199 Let's do a quick demo. 21 00:01:29,199 --> 00:01:34,239 So let me start by using systemctl list dependencies. 22 00:01:34,239 --> 00:01:35,239 Why not? 23 00:01:35,239 --> 00:01:36,239 Boot.mount. 24 00:01:36,239 --> 00:01:37,239 It's one of the mount targets. 25 00:01:37,239 --> 00:01:42,080 And here we can see it doesn't have very many dependencies. 26 00:01:42,080 --> 00:01:47,120 And if you do that for another service like sshd.service, there you can see everything 27 00:01:47,120 --> 00:01:51,480 that is required to get sshd.service. 28 00:01:51,480 --> 00:01:57,400 Look at the green dots because the green dots indicate what should really be there. 29 00:01:57,400 --> 00:02:02,779 Now I want to show you a demo where I'm going to create a dependency myself. 30 00:02:02,779 --> 00:02:09,080 In order to do so, I need to install the vsftpd service. 31 00:02:09,080 --> 00:02:15,639 And then I'm going to use systemctl edit on httpd.service. 32 00:02:15,639 --> 00:02:17,759 And in the edit, I'm doing it a nice way. 33 00:02:17,759 --> 00:02:22,839 I want to have this in the override file so that my edits are protected from system 34 00:02:22,839 --> 00:02:23,839 updates. 35 00:02:23,839 --> 00:02:37,320 So I'm going to use unit and requires is vsftpd.service, which happens to be the name of my vsftpd service. 36 00:02:37,320 --> 00:02:45,240 Now I'm using psaox.pipe.grep.ftp to show you that currently we don't have any vsftpd. 37 00:02:45,240 --> 00:02:51,080 Now I'm going to use systemctl restart httpd.service. 38 00:02:51,080 --> 00:02:53,160 And I'm doing my psaox again. 39 00:02:53,160 --> 00:02:54,160 And look at that. 40 00:02:54,160 --> 00:02:56,559 vsftpd is started as well. 41 00:02:56,559 --> 00:02:59,320 Can we find any information about it? 42 00:02:59,320 --> 00:03:02,839 Systemctl status vsftpd. 43 00:03:02,839 --> 00:03:05,080 Without the service, it defaults to service. 44 00:03:05,080 --> 00:03:11,279 I can see that it is started, but you don't really see anything about the dependency relation, 45 00:03:11,279 --> 00:03:14,000 the reason why it has been started. 46 00:03:14,000 --> 00:03:20,240 And on the httpd, well, we can see that httpd has an override.conf. 47 00:03:20,240 --> 00:03:23,839 But for the rest of it, we don't see the dependency relation either. 48 00:03:23,839 --> 00:03:28,559 So you really need to figure out how it works. 49 00:03:28,559 --> 00:03:32,119 And that is where systemctl list dependencies can come in handy.