1 00:00:07,380 --> 00:00:09,960 - [Narrator] In this video we'll talk about dependencies, 2 00:00:09,960 --> 00:00:12,693 dependencies between different systemd units. 3 00:00:13,680 --> 00:00:16,170 Different statements can be used in the Unit section 4 00:00:16,170 --> 00:00:18,930 to define unit file dependencies. 5 00:00:18,930 --> 00:00:22,260 There is Before, which means that this unit starts 6 00:00:22,260 --> 00:00:24,033 before the specified unit. 7 00:00:24,870 --> 00:00:28,440 And After, which obviously means that this unit starts 8 00:00:28,440 --> 00:00:30,393 when the specified unit is started. 9 00:00:31,620 --> 00:00:35,010 There is a Requires, which means that when this unit starts 10 00:00:35,010 --> 00:00:37,590 the unit listed here is also started. 11 00:00:37,590 --> 00:00:41,013 And if the specified unit fails, this one also fails. 12 00:00:42,060 --> 00:00:43,680 And there is Wanted. 13 00:00:43,680 --> 00:00:46,833 When this unit starts, the unit listed here is also started. 14 00:00:48,100 --> 00:00:51,327 Now even if you can manage dependencies in units 15 00:00:51,327 --> 00:00:53,520 you should consider using targets 16 00:00:53,520 --> 00:00:56,010 for more consistent dependency management. 17 00:00:56,010 --> 00:00:58,170 It's easy to have an overview of everything 18 00:00:58,170 --> 00:00:59,340 that is going on, 19 00:00:59,340 --> 00:01:02,283 but for now let's create some dependencies. 20 00:01:04,950 --> 00:01:08,890 Okay, let me start by using dnf install vsftpd 21 00:01:12,153 --> 00:01:14,986 (keyboard clicks) 22 00:01:19,409 --> 00:01:21,159 And systemctl status httpd. 23 00:01:26,400 --> 00:01:29,460 As you can see, loaded, disabled, inactive. 24 00:01:29,460 --> 00:01:30,960 That's exactly what we need. 25 00:01:30,960 --> 00:01:35,310 Loaded means that systemd knows which unit file to use 26 00:01:35,310 --> 00:01:37,113 and that is about it. 27 00:01:38,400 --> 00:01:41,460 For the rest of it, this unit currently is doing nothing. 28 00:01:41,460 --> 00:01:43,323 Same case for vsftpd. 29 00:01:44,250 --> 00:01:49,217 Now I'm going to use systemctl edit httpd dot service 30 00:01:51,540 --> 00:01:56,373 And I'm going to edit the unit configuration. 31 00:01:59,220 --> 00:02:03,813 Requires is vsftpd dot service. 32 00:02:07,947 --> 00:02:11,310 And I'm using systemctl start. 33 00:02:11,310 --> 00:02:15,093 No, before doing that let me use ps aux pipe grep ftp. 34 00:02:18,870 --> 00:02:22,120 Just so we agree that there is no vsftpd service running 35 00:02:23,099 --> 00:02:23,932 at this moment 36 00:02:23,932 --> 00:02:27,480 and now I can use systemctl start httpd. 37 00:02:27,480 --> 00:02:29,908 This is a systemd ctl start, 38 00:02:29,908 --> 00:02:32,700 systemctl start doesn't make it persistent 39 00:02:32,700 --> 00:02:35,204 that would need systemctl enabled, 40 00:02:35,204 --> 00:02:38,493 but I don't need it to be persistent at this moment. 41 00:02:39,780 --> 00:02:44,780 What I need is httpd to be starting 42 00:02:44,970 --> 00:02:49,050 and what we also need is to see 43 00:02:49,050 --> 00:02:52,860 that suddenly vsftpd is running as well 44 00:02:52,860 --> 00:02:56,970 and that's what you obtain by using a Requires. 45 00:02:56,970 --> 00:03:00,960 Now as I was mentioning a Requires isn't very clear 46 00:03:00,960 --> 00:03:03,510 to analyze dependency relations 47 00:03:03,510 --> 00:03:06,990 so it's probably much better to make sure that vsftpd, 48 00:03:06,990 --> 00:03:10,500 as well as httpd, are just in the same target 49 00:03:10,500 --> 00:03:12,690 and they're also WantedBy section. 50 00:03:12,690 --> 00:03:15,090 WantedBy is not as strong as Requires 51 00:03:15,090 --> 00:03:17,100 but by putting them in the same target 52 00:03:17,100 --> 00:03:19,440 you make it easier to see the logical relation 53 00:03:19,440 --> 00:03:20,640 between the two of them.