1 00:00:06,720 --> 00:00:07,950 - Okay, so in this lab, 2 00:00:07,950 --> 00:00:10,650 we need to reconfigure the httpd service. 3 00:00:10,650 --> 00:00:12,450 Now the fact is that we have already 4 00:00:13,350 --> 00:00:16,650 applied quite some configuration to httpd. 5 00:00:16,650 --> 00:00:20,160 And let's change it the nasty way. 6 00:00:20,160 --> 00:00:21,570 First, I'm going to make sure 7 00:00:21,570 --> 00:00:24,360 that we use systemctl stop httpd. 8 00:00:24,360 --> 00:00:25,590 Can't be running. 9 00:00:25,590 --> 00:00:26,583 Double checking. 10 00:00:29,070 --> 00:00:30,480 It's not running. 11 00:00:30,480 --> 00:00:33,426 Now I am going into 12 00:00:33,426 --> 00:00:37,620 /etc/systemd/system/ where we have 13 00:00:37,620 --> 00:00:40,020 httpd.service.d. 14 00:00:40,020 --> 00:00:42,930 In which there is override.conf. 15 00:00:42,930 --> 00:00:45,810 Now the httpd service, like anything is configured 16 00:00:45,810 --> 00:00:47,970 in such a way that it's checking 17 00:00:47,970 --> 00:00:50,820 if there is an /etc/systemd/system/ 18 00:00:50,820 --> 00:00:53,610 name of the service service.d directory. 19 00:00:53,610 --> 00:00:56,130 And if there is, it's going to include it. 20 00:00:56,130 --> 00:01:00,480 Now, if there is not, rm -rf on httpd.service.d 21 00:01:00,480 --> 00:01:02,640 it's not going to include it. 22 00:01:02,640 --> 00:01:05,670 Now this is one of these cases where you really must do 23 00:01:05,670 --> 00:01:08,583 a systemctl daemon-reload. 24 00:01:09,540 --> 00:01:12,164 Just to make sure that systemctl 25 00:01:12,164 --> 00:01:15,900 is fetching the latest configuration 26 00:01:15,900 --> 00:01:17,160 and it'll accept the fact 27 00:01:17,160 --> 00:01:19,173 that you have just removed everything. 28 00:01:20,640 --> 00:01:23,910 So what is happening if we now use systemctl cat 29 00:01:23,910 --> 00:01:26,013 on httpd.service? 30 00:01:26,850 --> 00:01:30,480 Well, as you can see there is just httpd.service 31 00:01:30,480 --> 00:01:32,130 and that's exactly what we want. 32 00:01:32,130 --> 00:01:36,333 We don't have any of this additional configuration anymore. 33 00:01:37,200 --> 00:01:40,920 I mean the auto restart option is a very nice option, 34 00:01:40,920 --> 00:01:43,530 but not if a service is triggered by a socket 35 00:01:43,530 --> 00:01:46,110 then there shouldn't be any auto restart. 36 00:01:46,110 --> 00:01:48,180 And just for sanity reasons, 37 00:01:48,180 --> 00:01:53,180 I also kicked out the vsftpd service that had required. 38 00:01:54,300 --> 00:01:56,820 And now we can move on and we can make sure 39 00:01:56,820 --> 00:01:58,860 that the service is going to be triggered 40 00:01:58,860 --> 00:02:01,770 while traffic is hitting port 80. 41 00:02:01,770 --> 00:02:04,380 Now before doing so, it's nice 42 00:02:04,380 --> 00:02:06,063 if we have some configuration. 43 00:02:07,080 --> 00:02:09,297 So echo hello world > 44 00:02:10,202 --> 00:02:14,550 /var/www/html/index.html. 45 00:02:14,550 --> 00:02:17,160 That's a simple index html. 46 00:02:17,160 --> 00:02:19,650 Otherwise we are starting an httpd service 47 00:02:19,650 --> 00:02:22,350 that doesn't have any content to service 48 00:02:22,350 --> 00:02:24,003 and that doesn't make sense. 49 00:02:24,840 --> 00:02:29,160 Now let's check out if there is any sockets that we can use. 50 00:02:29,160 --> 00:02:33,850 systemctl list-unit-files -t socket 51 00:02:35,610 --> 00:02:37,980 is showing us all the different sockets. 52 00:02:37,980 --> 00:02:40,350 And now look at that. 53 00:02:40,350 --> 00:02:43,260 We even have an httpd.socket. 54 00:02:43,260 --> 00:02:44,880 That's even better. 55 00:02:44,880 --> 00:02:49,590 Before using it, systemctl cat on httpd.socket 56 00:02:49,590 --> 00:02:51,210 is showing us what? 57 00:02:51,210 --> 00:02:55,530 Is showing that this really has everything that we need. 58 00:02:55,530 --> 00:02:57,480 So I'm just going to use 59 00:02:57,480 --> 00:03:02,230 systemctl enable --now httpd.socket 60 00:03:03,990 --> 00:03:05,550 to start the socket. 61 00:03:05,550 --> 00:03:08,010 And next I am going 62 00:03:08,010 --> 00:03:11,550 to access it using 63 00:03:11,550 --> 00:03:14,943 curl http://localhost, 64 00:03:16,350 --> 00:03:19,140 which is giving me hello world. 65 00:03:19,140 --> 00:03:23,160 And systemctl status httpd, 66 00:03:23,160 --> 00:03:24,300 do we see anything? 67 00:03:24,300 --> 00:03:25,950 Yeah, we see it is running 68 00:03:25,950 --> 00:03:28,860 triggered by httpd.socket. 69 00:03:28,860 --> 00:03:31,650 So this is really telling us that it is running 70 00:03:31,650 --> 00:03:34,650 since seven seconds ago triggered by the socket. 71 00:03:34,650 --> 00:03:36,510 And that's exactly what we wanted. 72 00:03:36,510 --> 00:03:38,613 This is what we are using sockets for.